Posts
33
Comments
186
Trackbacks
0
Date/Time formats in SQL Server

In SQL server a column with datatype of DateTime stores the time to the millisecond, but many times you just like to show the date and time only upto the second.

Although there are many ways to achieve this, I'm just going to show the couple of possible ways -

1.)

SELECT CONVERT(VARCHAR,GETDATE(),120)

This would yield the current date time in YYYY-MM-DD HH:MM:SS (ofcourse depends on your regional setting)

2.) You can get the millisecond part from the getdate() function and subtract it with the getdate() to leave you with time only upto second.

SELECT DATEADD(ms, -DATEPART(ms,GetDate()),GetDate())

As I mentioned earlier, these are just some of the possible ways to acheive the desired result.

The post www.sql-server-helper.com/tips/date-formats.aspx has some very good collection to acheive various formats in date/time in SQL.

Hope this helps!

 

posted on Thursday, June 9, 2011 12:21 PM Print
Comments
Gravatar
# re: Date/Time formats in SQL Server
irhakhalid
4/16/2018 1:52 PM
Its good to see you have a Welcome message for your blog but you can expand this message to tell more about this website and your future project which you have plan to cover in this website. In this way user acknowledge your plan and touch with your website. However, I need online essay review but i hope my this opinion will matter for you to make your blog good.
Gravatar
# re: Date/Time formats in SQL Server
sunam89
4/24/2018 2:23 PM
This website help to learn the working of SQL server because a lot of developer have issue with this kind of effort. So, those people can help from this site to make their work more easy. Hope, I actually want karamba casino and there are good stuff for us to learn more things.

Post Comment

Title *
Name *
Email
Comment *  
Verification