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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on Select Stmt -DateTime- Please!

Status
Not open for further replies.

SeaninSeattle

IS-IT--Management
Sep 17, 2001
53
US
This is seem pretty stupid to most of you, but I need help writing a select statement that will pull a datetime field.

The deal is, however, that I need it to pull just the year, month and day (YYYY, MM,DD) and not the time. Does anyone know the short easy way to do that

- or -

alternatively, a way to set the formatting on the table itself so that it only keeps YYYY-MM-DD format?

Thanks,
//sse
Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Select convert(char(10),YourDate,1) as theDate from your table.

Look up the convert function. The above will retrieve the short date.
 
You can also use Left(char(10), DateTimeCol). SQL Server will store the date and time, always. I you insert just a date the time will be 00:00:00.000 which signifies 12 AM. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
You may also want to check out DatePart. I know in a previous lifetime I had to concatenate dateparts of the datetime field in order to get the exact format I was looking for.

I don't remember the exact syntax for DatePart but it should be in Books On Line Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
Yeah - I got it. Thanks everyone for your help!

//sse Sean Engle
Admin/DirIS
ssengle@bswusa.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top