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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Setting SQL server default date

Author  Topic 

android.sm
Starting Member

36 Posts

Posted - 2011-05-14 : 16:31:14
How do I set the current date field in sql server 2008 express to something like this:

14 May 2011 10:00pm

At the moment I use GETDATE() - but would like to format it to the above.

SELECT CONVERT(VARCHAR(20), GETDATE(), 100) returns me May 14 2011 9:22PM - which is good enough for me. But how do I apply that statement in the table designer field?

Thanks All!

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-05-14 : 16:40:15
Never, never, never store a date in a varchar column. Store as a datetime and do your formatting in the queries of front end.

You're setting yourself up for massive pains putting a date into a varchar.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

android.sm
Starting Member

36 Posts

Posted - 2011-05-14 : 19:34:44
Thanks for getting back.

The front end has no date capturing hence why I'm setting the default value the getdate() to capture current date the moment a record is created - and the column in the table is datetime.
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-05-15 : 04:24:13
Cool, then you're all set. Just put the default as getdate() and do the formatting when you query the data. A datetime column has no defined format (format is purely and only a string concept)

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -