Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Compare TextBox date to today

Reply
Thread Tools

Compare TextBox date to today

 
 
David C
Guest
Posts: n/a
 
      03-27-2009
I have the following code in my aspx page and I don't think the date
comparison is working and I need help making it work. The line that I think
is a problem is If CDate(tb.Text) < CDate(System.DateTime.Today()) Then

Dim tb As TextBox
Dim btn As Button
Dim row As FormViewRow = fvTickler.Row
If fvTickler.CurrentMode = FormViewMode.ReadOnly Then
tb = row.FindControl("txtExpireDate")
If (Not tb Is Nothing) Then
If tb.Text <> "" Then
If CDate(tb.Text) < CDate(System.DateTime.Today()) Then
'Tickler expired prior to today so make form
background red
fvTickler.RowStyle.BackColor = Drawing.Color.Red
End If
.....

Thanks.
David


 
Reply With Quote
 
 
 
 
imransyed63 imransyed63 is offline
Member
Join Date: May 2006
Posts: 31
 
      03-29-2009
Use,
Dim noOfDays As Long = DateDiff(DateInterval.Day, CDate(tb.Text), System.DateTime.Today())

noOfDays will be the date difference between tb.text & Today.

noOfDays < 0 ==> CDate(tb.Text) > System.DateTime.Today()
noOfDays > 0 ==> CDate(tb.Text) < System.DateTime.Today()
noOfDays = 0 ==> CDate(tb.Text) = System.DateTime.Today()
 
Reply With Quote
 
 
 
 
Niall
Guest
Posts: n/a
 
      03-31-2009
Hi David,

Are the dates in the same format or are they getting converted to valid
datetimes??

Niall


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      03-31-2009
On Mar 27, 7:39*pm, "David C" <(E-Mail Removed)> wrote:
> I have the following code in my aspx page and I don't think the date
> comparison is working and I need help making it work. The line that I think
> is a problem is If CDate(tb.Text) < CDate(System.DateTime.Today()) Then
>
> * * * * Dim tb As TextBox
> * * * * Dim btn As Button
> * * * * Dim row As FormViewRow = fvTickler.Row
> * * * * If fvTickler.CurrentMode = FormViewMode.ReadOnly Then
> * * * * * * tb = row.FindControl("txtExpireDate")
> * * * * * * If (Not tb Is Nothing) Then
> * * * * * * * * If tb.Text <> "" Then
> * * * * * * * * * * If CDate(tb.Text) < CDate(System.DateTime.Today()) Then
> * * * * * * * * * * * * 'Tickler expired prior to today so make form
> background red
> * * * * * * * * * * * * fvTickler.RowStyle.BackColor = Drawing.Color.Red
> * * * * * * * * * * End If
> * * * * .....
>
> Thanks.
> David


Your code looks correct, where do you mean it is "not working"? If
date is specified in a correct format than it should work. The only
thing is that you forget to check if format is correct. For example,
if date is "32/32/2008" you will get an exception. It means to avoid
this you need to add for example following code

Dim dateValue As Date
If Date.TryParse(tb.Text, dateValue) Then
If dateValue < System.DateTime.Today() Then
....
 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      03-31-2009
It was the value in the TextBox. Thanks.
David
"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On Mar 27, 7:39 pm, "David C" <(E-Mail Removed)> wrote:
> I have the following code in my aspx page and I don't think the date
> comparison is working and I need help making it work. The line that I
> think
> is a problem is If CDate(tb.Text) < CDate(System.DateTime.Today()) Then
>
> Dim tb As TextBox
> Dim btn As Button
> Dim row As FormViewRow = fvTickler.Row
> If fvTickler.CurrentMode = FormViewMode.ReadOnly Then
> tb = row.FindControl("txtExpireDate")
> If (Not tb Is Nothing) Then
> If tb.Text <> "" Then
> If CDate(tb.Text) < CDate(System.DateTime.Today()) Then
> 'Tickler expired prior to today so make form
> background red
> fvTickler.RowStyle.BackColor = Drawing.Color.Red
> End If
> .....
>
> Thanks.
> David


Your code looks correct, where do you mean it is "not working"? If
date is specified in a correct format than it should work. The only
thing is that you forget to check if format is correct. For example,
if date is "32/32/2008" you will get an exception. It means to avoid
this you need to add for example following code

Dim dateValue As Date
If Date.TryParse(tb.Text, dateValue) Then
If dateValue < System.DateTime.Today() Then
....


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Notice the date today? What happened 40 years ago today? richard Computer Support 10 07-29-2009 08:20 PM
How do I compare today's date to date in string joeyej Javascript 7 04-06-2006 09:45 PM
get today's date and compare to txt Field peashoe@yahoo.com ASP General 8 01-24-2005 08:22 PM
simple question about a textbox and today's date ..noob TN Bella ASP .Net 5 06-18-2004 04:31 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments