Solved

# Problem with Dates in Do While (dr.Read())

Posted on 2006-04-21
473 Views
What's wrong with this?

if (dr("Date_Only") = (01/01/1900)) then
(row("Date_Only")= (04/22/2006))
else
row("Date_Only")=dr("Date_Only")
end if
0
Question by:net_susan

LVL 17

Expert Comment

what's error you'r getting?
0

LVL 142

Expert Comment

this should work better, but not sure:
if (dr("Date_Only") = "01/01/1900") then
(row("Date_Only")= "04/22/2006")
else
row("Date_Only")=dr("Date_Only")
end if

the isse with yours is that you have a simple numerical division (1/1)/1900 etc, which is NOT a date, even if it looks at the first sight as one.
0

LVL 17

Expert Comment

may be you need to do:

if (dr("Date_Only") == DateTime.MinValue) then
row("Date_Only") = Convert.ToDateTime(04/22/2006);
else
row("Date_Only") = Convert.ToDateTime(dr("Date_Only").ToString());
end if
0

LVL 17

Expert Comment

if (dr("Date_Only") == DateTime.MinValue) then
row("Date_Only") = Convert.ToDateTime("04/22/2006");
else
row("Date_Only") = Convert.ToDateTime(dr("Date_Only").ToString());
end if
0

LVL 1

Author Comment

This got a fast response.  :)

BC30035: Syntax error.

for both ways.
0

LVL 17

Expert Comment

sorry in vb:

if dr("Date_Only") = DateTime.MinValue then
row("Date_Only") = Convert.ToDateTime("04/22/2006")
else
row("Date_Only") = Convert.ToDateTime(dr("Date_Only").ToString())
end if
0

LVL 1

Author Comment

not lem's, one sec...
0

LVL 1

Author Comment

Lem's failed on this line:

if (dr("Date_Only") == DateTime.MinValue) then

Expression expected.
0

LVL 1

Author Comment

Ok, that didn't fail.
0

LVL 17

Expert Comment

try:
if dr("Date_Only") = "01/01/1900" then

or

if dr("Date_Only") = Convert.ToDateTime("01/01/1900") then
0

LVL 1

Author Comment

but...

what is this? if dr("Date_Only") = DateTime.MinValue then

is the MinValue actually 01/01/1900?

because as far as I know, it's a date I created.
0

LVL 17

Expert Comment

yes the minvalue is "01/01/1900"... but if it don't work for you use the your string
0

LVL 1

Author Comment

this seems to work:

if dr("Date_Only") = "01/01/1900" then

but, it shows as 4/22/2006 12:00:00 AM

when I had the stored procedure bring it down to 4/22/2006 before.
0

LVL 17

Accepted Solution

ummm then:

if dr("Date_Only") = "01/01/1900" then
row("Date_Only") = Convert.ToDateTime("04/22/2006").ToString().SubString(0,10)
else
row("Date_Only") = Convert.ToDateTime(dr("Date_Only").ToString()).ToString().SubString(0,10)
end if
0

LVL 1

Author Comment

maybe it did work. it didn't fail. I haven't tested it much yet, but if you could just get the time out we'll be good to go!

0

LVL 1

Author Comment

Yippee.
0

## Featured Post

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…