Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone i have a question im using this code to get date
CDate(IIf(IsDate(dr("ApplicationDate").ToString), dr("ApplicationDate").ToString, "06/17/2013")) 

yet im using this with a scenario i import .csv file then it will save also in my db which in this file there is no date inserted.. but it is already imported the date 06/17/2013 still viewed in my site im making my question is whta code that suits the code that im trying to update when uploading to update my date that 06/17/2013 will replace with a new date wherein i already update and insert in my database like this

insert (applicationdate) values (getdate())


thanks in advance
Posted
Updated 24-Jun-13 18:42pm
v2
Comments
Jignesh Khant 25-Jun-13 1:15am    
When you insert date using getdate() it inserts date in yyyy-MM-dd format and the one you are using is different, it will consider that format as string and hence will throw runtime error. So try using yyyy-MM-dd format.
Maciej Los 25-Jun-13 1:29am    
What is dr?
How do you fetch the data?
You need to be more specific and provide more details...

1 solution

If I understood your question you need to use DateTime.Now[^] in place of "06/17/2013".

So, the code will be:

VB
CDate(IIf(IsDate(dr("ApplicationDate").ToString), dr("ApplicationDate").ToString, DateTime.Now.ToString)) 
 
Share this answer
 
Comments
Member 10033107 25-Jun-13 2:29am    
Hi Andrew! your approach to my question is right to your understanding since i change datetime.now.tostring it gets an error so i change it as Today.TimeOfDay.ToString yet i got an error to quoted: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. it means it should be specific so how can i do that to fix this?
chaau 25-Jun-13 19:59pm    
What happens if you use just Today.ToString?
Member 10033107 26-Jun-13 2:56am    
hi Andrew.. i just use Today.Date and its fine working now thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900