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

how could I get the date in "mm/dd/yy" format using getdate() function

Status
Not open for further replies.

nannu

Programmer
Jul 2, 2000
5
0
0
US
In SQL 7.0: <br>I am retrieving last 10 records from the database, where the condition is based on the date column, which is generated by using the getdate() function. The particulat field is defined in the database as datetime(), since the getdate() get the timestamp with it, I could not execute the query, all the values are scred up. help me to come over the problem. Thanks
 
getdate() will generate a full timestamp, but there are a number of date functions that you could use to help. Two of which are:<br><br><FONT FACE=monospace>DATEPART(datepart,date)</font><br>where datepart is year, quarter, month, dayofyear, day, week, etc. will give you the date in the units you want.<br><br><FONT FACE=monospace>DATEDIFF(datepart,startdate,enddate)</font><br>will compare two dates using the units specified.<br><br>The full set of functions are in Books On Line. <p> <br><a href=mailto: > </a><br><a href= home</a><br>
 
select convert(dateTime,convert(char(20),getdate(),101))<br><br>solves the problem of elimating the time, that is it sets the hh:mm:ss to 00:00:00.<br>It works fine
 
Try the following :<br><br>SELECT CONVERT(VARCHAR,GETDATE(),103)<br><br>or<br><br>SELECT CONVERT(VARCHAR,GETDATE(),3)<br><br>The first gives a 4 digit year, the second a 2 digit year.<br><br>Looking at the CAST & CONVERT functions in books online gives a multitude of possible return formats.<br><br>Hope it helps<br><br>Chris.
 
Hi, I'm having the same problem but in the other sense, I need to remove the date from a datetime field but none of the CONVERT styles seem to work. Anybody knows what can I do?
Thanks,

Juan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top