|
-
Jan 24th, 2008, 07:04 PM
#1
Thread Starter
Addicted Member
-
Jan 24th, 2008, 07:23 PM
#2
Re: [2005] Date Format - TROUBLE
Is there a reason that you chose to use a TextBox instead of the DateTimePicker, which is designed for dates?
If you do want to stick with a TextBox then you can't use the '<' operator on strings because it will compare them alphabetically. If you want to compare dates then you have to compare Date objects:
vb.net Code:
Dim input As Date If Date.TryParseExact(Me.TextBox1.Text, _ "dd/MM/yyyy", _ Nothing, _ Globalization.DateTimeStyles.None, _ input) Then If input < Date.Today Then 'The specified date is before today's date. End If Else 'Invalid input. End If
Note also that if you specify "dd/MM/yyyy" as the format the the user will have to include leading zeroes on single-digit days. It might be more appropriate to use "d/MM/yyyy", which will accept single- or double-digit days.
-
Jan 24th, 2008, 08:00 PM
#3
Thread Starter
Addicted Member
Re: [2005] Date Format - TROUBLE
The TextBox is ReadOnly... user does not type a date.
My computer date is 25.01.2008 and i have into the txt_pana_la_data.text the value 10/12/2007 and it's not working! Why ?!?!
This code i've used!
Code:
Dim input As Date
If Date.TryParseExact(Me.txt_pana_la_data.Text, "dd/MM/yyyy", Nothing, Globalization.DateTimeStyles.None, input) Then
If input < Date.Today Then
Me.txt_stare_permis.Text = "Expirat"
Me.btn_prelungire.Enabled = True
Me.Validate()
Me.permis_BindingSource.EndEdit()
Me.permis_TableAdapter.Update(Me.permis_DataSet.lista_abonati)
Me.permis_BindingSource.Clear()
Me.permis_TableAdapter.Fill(Me.permis_DataSet.lista_abonati)
End If
Else
'Invalid input.
End If
I'm still learning VB.NET
Sorry for my bad english
Thanks for your help
-
Jan 24th, 2008, 08:37 PM
#4
Re: [2005] Date Format - TROUBLE
If your TextBox is ReadOnly then why do you need to test the value in the TextBox at all? That value must have come from somewhere, and that somewhere is presumably a Date value. You should be testing THAT value against the current Date.
-
Jan 25th, 2008, 05:42 AM
#5
Thread Starter
Addicted Member
-
Jan 25th, 2008, 05:47 AM
#6
Re: [2005] Date Format - TROUBLE
Why are you reading a text value from the database? If it's a date then why is it not stored as a date? Do you store numbers as text or as numbers? If you store numbers as numbers then why don't you store dates as dates?
Also, my code does what it's supposed to do. How would I know what you're doing wrong if you haven't shown me what you are doing?
-
Jan 25th, 2008, 05:56 AM
#7
Thread Starter
Addicted Member
-
Jan 25th, 2008, 08:06 AM
#8
Re: [2005] Date Format - TROUBLE
Your txt_pana_la_data TextBox is bound to a column from your DataTable. That columns should contain Date values and you should be comparing that data to the current date. You should not be parsing the string in the TextBox and your DataColumn should not contain strings.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|