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
 Date format in Column?

Author  Topic 

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-15 : 11:02:25

Hi
I have a Date column with default value set up as below

(getdate()) --- This giving the format - 15/04/2008 15:36:57

How do I store the date as 15042008 or 15/04/2008 or 15-04-2008

Adavance thanks


harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-15 : 11:07:24
You can not store date in your custom format,but you format it while retrieving using CONVERT function.


For example to get dd/mm/yyyy

select convert(varchar(10),getdate(), 103)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-15 : 11:11:48
You need to be concerned about format of date only during retrieval of data.
Go to Top of Page

Vaishu
Posting Yak Master

178 Posts

Posted - 2008-04-15 : 11:18:11
Hi

Thanks for the reply. Is it possible to convert as yyyymmdd (without '/')

quote:
Originally posted by harsh_athalye

You can not store date in your custom format,but you format it while retrieving using CONVERT function.


For example to get dd/mm/yyyy

select convert(varchar(10),getdate(), 103)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-04-15 : 11:19:32
[code]select convert(varchar(10),getdate(), 112)[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-16 : 03:06:53
quote:
Originally posted by Vaishu

Hi

Thanks for the reply. Is it possible to convert as yyyymmdd (without '/')

quote:
Originally posted by harsh_athalye

You can not store date in your custom format,but you format it while retrieving using CONVERT function.


For example to get dd/mm/yyyy

select convert(varchar(10),getdate(), 103)


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"




Where do you want to show data?

Madhivanan

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

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2008-04-16 : 03:48:26
Look up CONVERT in BOL, it will give you a list of all supported formats. Formating is however recomended to do in the presentation layer...

--
Lumbago
Go to Top of Page
   

- Advertisement -