AllExperts > Active Server Pages Programming (ASP) 
Search      
Active Server Pages Programming (ASP)
Volunteer
Answers to thousands of questions
 Home · More Active Server Pages Programming (ASP) Questions · Answer Library  · Encyclopedia ·
More Active Server Pages Programming (ASP) Answers
Question Library

Ask a question about Active Server Pages Programming (ASP)
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Ashley Brazier
Expertise
Main focus is ASP, SQL Server 2000 & 2005

Experience
Over 6 years experience.

Education/Credentials
BCs Honours Software Design and Networks

 
   

You are here:  Experts > Computing/Technology > Business Software > Active Server Pages Programming (ASP) > Convert string into date...using ASP

Active Server Pages Programming (ASP) - Convert string into date...using ASP


Expert: Ashley Brazier - 2/12/2009

Question
QUESTION: Hi Ashley, I am having trouble converting a string in the format of YYYY-MM-DD into MM/DD/YYYY. I tried using the cdate function, which works well, except that I have some null records in that field. It breaks right when a date record has a null.

ANSWER: Hi,

Have you tried
if yourdate = "" then

Or

if isnull(yourdate) then

Can you send sample code?

---------- FOLLOW-UP ----------

QUESTION: strNewDate = (rsdept("fhnpro"))

response.write"<td align=center><font>" & strNewDate & "</font></td>" & _

The output appears as: 2009-02-20

I need it to appear as: 02/20/2009

This code below will work and format the date correctly, but will break when a null appears.

"<td align=center><font>" & cdate(strNewDate) & "</font></td>" & _

From what I have read, the cdate function doesn't work with null values

This is the error that I get with the cdate function when a null value appears:
Microsoft VBScript runtime error '800a005e'
Invalid use of Null: 'cdate'

Yes, I have tried the isnull if statement and could not get it to work. Although, i wouldn't doubt if it was a syntax issue.

Answer
Hi,

Your best bet is to check if its null before trying to display it.

Is the error coming up on this line:

"<td align=center><font>" & cdate(strNewDate) & "</font></td>" & _

if it does, what is the value in the database, is it NULL or the default 01/01/1900?

try this, put this after the strNewDate = (rsdept("fhnpro"))

if isnull(strNewDate) OR strNewDate <> "" then
strNewDate = cdate(strNewDate)
else
strNewDate = "NULL DATE HERE"
end if

Change this line:-
"<td align=center><font>" & cdate(strNewDate) & "</font></td>" & _
to
"<td align=center><font>" & strNewDate & "</font></td>" & _


Let us know how you get on

Cheers  

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.