DateTime Manipulation: Date Part or Time Part

There are times when using SQL server 2000 or 2005 , you really want to use either the date-part or the time-part of a datetime value. But, you would still want to use it as a datetime value for comparison. Usually, as a solution, you would try and build a new datetime by converting the current datetime into a string or extracting the day, month, year etc. from the datetime using the respective SQL functions.

The SQL server’s default language settings may sometimes poses problems when building the new datetime using various parts of the datetime.

However, I found the following solution from here. It is a clean solution to convert the datetime to midnight or keep the time-part but change the date-part to 1900-01-01.

Here is the code:
SELECT GETDATE() AS [CURRENT_DATE],
       CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME) AS [DATE_PART],
       CAST(CAST(GETDATE() AS FLOAT) - FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME) AS [TIME_PART]

2 thoughts on “DateTime Manipulation: Date Part or Time Part

  1. There are specific breeds lower susceptible to chocolate
    however never givve your dog chocolate by choice.
    They may also tump to get attention, which might mean they want out of the cage to
    play and be with the family. Findd Indian astrology wioth
    horoscope and live astrological prediction , aries
    horoscope, daily, monthly, yeaarly analysis oof birth chart and individual prediction off all planet with gemstone.

Leave a comment