Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help - UK DateTime Format

Author  Topic 

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-27 : 11:16:57
Dear Friends,

The following query on one server give me UK dateformat, but on other server the datetime format is coming in USA FORMAT.

select convert(datetime,getdate(),103)

I don't understand why it is working on one server and not working on the other. Please help.

Thanks.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2010-09-27 : 11:28:05
Try select convert(varchar,getdate(),103) or select convert(datetime,getdate(),120) instead.
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-27 : 11:54:19
quote:
Originally posted by RickD

Try select convert(varchar,getdate(),103) or select convert(datetime,getdate(),120) instead.



Thanks RickD,

The following query is not showing in UK format
select convert(datetime,getdate(),103)
output: 2010-09-27 18:49:30.170.

select convert(varchar,getdate(),103)
output: 27/09/2010

Is there a way to get output in UK FORMAT(with date and time) AS
REQUIRED OUTPUT : 27/09/2010 18:49:30.170.

Many Thanks.

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-09-27 : 12:34:57
"Is there a way to get output in UK FORMAT(with date and time) AS
REQUIRED OUTPUT : 27/09/2010 18:49:30.170.
"

Not directly, no. You will have to use string manipulation / concatenation. Better would be to format the dates in the front end (that way they are passed unambigiously to the front end in native date format).

Note that

convert(datetime,getdate(),103)

is ambiguous. CONVERT is expecting to see the first two parameters as Char/Datetime (convert from Datetime to Char) or Datetime/Char (Convert from Char to Datetime) and then will use the third parameter as a definition of the format, whereas your first two parameters are both datetime datatype

The various formats numbers are in the DOCs, but there are not many and they are specific formats only, rather than (for example) a format template.

This will get you close to what you want, but won;t give you milliseconds:

select convert(varchar(10), getdate(),103) + ' ' + convert(varchar(8), getdate(),108)

you'll need to fiddle about with format 109 to get the millisecond (there may be other formats that are also helpful as a starting point)
Go to Top of Page

amodi
Yak Posting Veteran

83 Posts

Posted - 2010-09-28 : 04:46:52
Thanks a Million Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-28 : 10:30:34
Also make sure to read this
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -