Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date time - datatypes 1

Status
Not open for further replies.

nread

Technical User
Oct 31, 2001
58
GB
Hi all,

Does anyone know if there is a simple way to select from a datetime field, something similar to that of TRUNC in Oracle...

I'm fairly new to SQL Server and seem to being having an absoloute nightmare with dates....!!

Any suggestions welcome....

Cheers
 
Can you be more specific.Please give some example about your desired result.

 
Do you mean trim certain fields off?
This trims 1st to 17th character date in UK format.

SUBSTRING(CONVERT(VarChar, dateTimeField, 113), 1, 17) AS 'someDate',

Try Programs -> SQL Server -> Books Online

SUBSTRING
CAST
CONVERT
Hope this helps a bit
 
You don't even need the substring command:

convert(varchar(17), getdate(), 113) does the same thing as mit99mh's suggestion.

-SQLBill
 
Cheers for that Bill - its way better than my suggestion
 
Cheers all, I needed to set the time to be 00:00:00 using
CAST(FLOOR(CAST(dtmDate AS FLOAT)) AS DATETIME).

I am now using Bills suggestion, thanks Bill....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top