470,594 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

FAQ Reformating the Dates in ASP.NET / MSSQL Database that has some <NULL> values

Issue - Reformating the Dates in ASP.NET from a MSSQL Database that has

<NULL> values in a SmallDateTime Field
to read "Dec 8, 2000" instead of "12/8/2000 12:00:00 AM"
(As you might already know "DateTime.Parse" will throw an exception
when it comes accross a <NULL> date value so some logic has to be
1) In the SQL statement that builds the DataSet I used 'coalesce' to
assign a temp bogus date that will never occur in my database to take
place of the <NULL> (01-01-1901)
"SELECT coalesce(inj_end,cast(" + Chr(39) + "1901-01-01" + Chr(39) + "
as datetime)) as inj_end
FROM inq_case
2) In the ASP page I have an IFF statement that pretty much says "If
you are "1901-01-01" you get formated as "" and if you are not you get
formated as "MMM d, yyyy"
<%# IIF ((dsCases.FieldValue("inj_end"*, Container) = "1/1/1901
AM"), "", DateTime.Parse(dsCases.FieldVa*lue("inj_end",
Container)).ToString("MMM d, yyyy")) %>
Notice I had to use "1/1/1901 12:00:00 AM" instead of "1901-01-01"
(That's VB.NET trying to help you with smalldatetime field from MSSQL)
Thats it!

Nov 19 '05 #1
0 1000

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.