Date and Time Formatting example

Ddd
Posted by Ddd under Sql Server category on | Points: 40 | Views : 1887
For date and time formatting use this command:-

select convert(varchar(30),getdate(),100)

output is:

Jan 11 2011 7:52PM

In the Convert function:

1)varchar(30): length of the string to be displayed

in the output:

2)getdate():current date

3)100: style number

Try with these style numbers
1 to 14
20 to 25
100 to 114
120 to 121, 126, 127, 130, 131



Some other styles:

i)style number:-105

The output
11-01-2011

ii) style number:-114

The output

19:53:07:230

Comments or Responses

Posted by: PandianS on: 1/11/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi

Can you please correct something in your example (Format Numbers)

The Possible format numbers are :
1 to 14
20 to 25
100 to 114
120 to 121, 126, 127, 130, 131

Apropos the range you have given like 99 to 114, It should be 100 to 114, Because format number 99 is not valid...

Kindly review and do the changes accordingly....

Cheers
www.sqlserverbuddy.blopgspot.com
Posted by: Ddd on: 1/12/2011 Level:Silver | Status: [Member] | Points: 10
Hi PandianS

,Thanks for the information

Ddd

Login to post response