Tuesday, February 26, 2013

T-SQL: Get current date and time

Functions available to get the current date and time

Function Result Return type
GETDATE() 2013-02-26 20:54:24.057 DATETIME
CURRENT_TIMESTAMP 2013-02-26 20:54:24.057 DATETIME
GETUTCDATE() 2013-02-26 20:09:17.467 DATETIME
SYSDATETIME() 2013-02-26 21:09:17.4680514 DATETIME2
SYSUTCDATETIME() 2013-02-26 20:09:17.4680514 DATETIME2
SYSDATETIMEOFFSET() 2013-02-26 21:09:17.4680514 +01:00 DATETIMEOFFSET

UTC means Coordinated Universal Time and is widely used as time standard in web applications. The result above were taken on a PC with the time zone (UTC+01:00). Note that the UTC functions return the time one hour before the rest.

CURRENT_TIMESTAMP is the recommended one as it is the ANSI equivalent of GETDATE()

Don't forget that if you only need the current DATE or TIME, you can cast the return of the above functions to a DATE or TIME

Example:

SELECT CAST(GETDATE() as DATE)

which will return

2013-02-26

For all DateTime functions visit the following link

5 comments:


  1. Packers And Movers Bangalore Local Household Shifting Service, Get Free Best Price Quotes Local Packers and Movers in Bangalore List, Compare Charges, Save Money And Time at
    Local Packers And Movers Bangalore

    ReplyDelete
  2. Packers and Movers Gurgaon Provide Reliable, Safe and Certified Service Provider list, Get Free ***Best Price Quotaition and Compare Charges. ???Hassle free Household Shifting Services, High Quality packing Material, Office Relocation, Car Transportaion, ###Local and Domestic Shifting Service @
    Packers And Movers Gurgaon

    ReplyDelete
  3. Packers and Movers Hyderabad Give Certified and Verified Service Providers, Cheap and Best ###Office Relocation Charges, ***Home Shifting, ✔✔✔Goods Insurance worth Rs. 10,000, Assurance for Local and Domestic House Shifting. Safe and Reliable Household Shifting Services in Hyderabad with Reasonable Packers and Movers Price Quotation @ Packers And Movers Hyderabad

    ReplyDelete
  4. Packers and Movers Pune Provide High Quality ***Household Shifting, Home/Office Relocation, Insurance, Packing, Loading, ###Car Transportation Service Pune and High experiences, Top Rated, Safe and Reliable, Best and Secure Packers and Movers Pune Team List. Get ✔✔✔Affordable Rate Charts and Compare Quotation and Save Money and Time @ Packers And Movers Pune

    ReplyDelete