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!

Convert int into datetime 1

Status
Not open for further replies.

CrystalStart

IS-IT--Management
Feb 3, 2005
185
US
Please help asap!

Have a field integer that is capturing calls in seconds
Need to convert into format hh:mm:ss HOW?
Thanks

Tried convert(datetime,fieldname)
gives:
1900-02-03 00:00:00
 
Try this. There may be better ways to do this.
Replace the 360 with the number of seconds you are attempting to convert


Select Convert(VarChar, DateAdd(second, 360, 0), 108)
 
what is varchar? I have an integer need to become datetime...thanks
 
The DateAdd function returns a DateTime Field. However, there is a date and a time component to this, and since you only want time... Converting it to a varchar with the formatting option of 108, will return ONLY the time part of the date time return value.

By the way, it should be pointed out that I am NOT an expert on date time calculations. However, this method should work as long as the duration does NOT span 1 full day.
 
Where am I suppose to indicate name of my field? Thanks
 
Replace the 360 in the SQL String with your field name

Ex.

Select Convert(VarChar, DateAdd(second, MyDurationField, 0), 108) As Duration
From MyTable
 
If you post your original SQL, I could help you a little better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top