Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All

Please Help me in converting the varchar '10/16/2014 10:20:20 PM' into datetime as i am having need to compare the dates
Posted
Comments
aarif moh shaikh 17-Oct-14 4:47am    
Where you want to Convert ... in SQL or Code Behind ??
[no name] 17-Oct-14 5:38am    
Store DateTime values as DateTimes and you won't have to do any conversion.

1 solution

You can use CAST or CONVERT function[^].

SQL
SELECT CONVERT(DATETIME, '10/16/2014 10:20:20 PM') AS MyDateTime


In case of convertion failed because of 'out of range' error message, use SET DATETIMEFORMAT command[^].

SQL
SET DATETIMEFORMAT mdy;
SELECT CONVERT(DATETIME, '10/16/2014 10:20:20 PM') AS MyDateTime
 
Share this answer
 
v2

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