maliary Posted April 18, 2009 Share Posted April 18, 2009 Hi , I have the following code ISNULL(CAST(T1.[DocDate] AS varchar(50)), 'Nothing') where T1.[DocDate] is null, the code correctly returns 'Nothing' if it is not null then the code returns the date but in varchar format e.g. Apr 17th 2009. I would like to display the date as 17/04/2009 is this possible ? Quote Link to comment https://forums.phpfreaks.com/topic/154637-solved-converting-varchar-to-datetime/ Share on other sites More sharing options...
mtoynbee Posted April 20, 2009 Share Posted April 20, 2009 These are the available date formats in MSSQL - not sure it supports the "th" or "st" or "rd" or "nd" suffixes... PRINT '1) HERE IS MON DD YYYY HH:MIAM (OR PM) FORMAT ==>' + CONVERT(CHAR(19),GETDATE()) PRINT '2) HERE IS MM-DD-YY FORMAT ==>' + CONVERT(CHAR(,GETDATE(),10) PRINT '3) HERE IS MM-DD-YYYY FORMAT ==>' + CONVERT(CHAR(10),GETDATE(),110) PRINT '4) HERE IS DD MON YYYY FORMAT ==>' + CONVERT(CHAR(11),GETDATE(),106) PRINT '5) HERE IS DD MON YY FORMAT ==>' + CONVERT(CHAR(9),GETDATE(),6) PRINT '6) HERE IS DD MON YYYY HH:MM:SS:MMM(24H) FORMAT ==>' + CONVERT(CHAR(24),GETDATE(),113) Here is the output from the above script: 1) HERE IS MON DD YYYY HH:MIAM (OR PM) FORMAT ==>Feb 5 2003 5:54AM 2) HERE IS MM-DD-YY FORMAT ==>02-05-03 3) HERE IS MM-DD-YYYY FORMAT ==>02-05-2003 4) HERE IS DD MON YYYY FORMAT ==>05 Feb 2003 5) HERE IS DD MON YY FORMAT ==>05 Feb 03 6) HERE IS DD MON YYYY HH:MM:SS:MMM(24H) FORMAT ==>05 Feb 2003 05:54:39:567 Quote Link to comment https://forums.phpfreaks.com/topic/154637-solved-converting-varchar-to-datetime/#findComment-814299 Share on other sites More sharing options...
maliary Posted April 20, 2009 Author Share Posted April 20, 2009 Thanks ! Quote Link to comment https://forums.phpfreaks.com/topic/154637-solved-converting-varchar-to-datetime/#findComment-814301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.