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!

Put 24hr time in SQL Datetime field 1

Status
Not open for further replies.

nmath

Programmer
Dec 12, 2003
47
0
0
US
I have an input box that is getting set with javascript to be the current date/time on the clients computer. When the form is posted the date and time is being stored in a DateTime field in SQL Server 2000. The time that shows up in the input box with javascript is in 24hr time which is what I want, however when it gets stored in the DB it is changed to AM/PM time. Does anyone know how to make the time stamp store as 24hr time which is what I am sending it to insert into the table? Thanks in advance for any suggestions!
 
nMath

Timestamp does not = a time field!!!!

use datetime or smalldatatime!

Timestamp is the rowversion of Oracle - it just tells us that the row has been modifed if it isn't the same. It does not represent a time value


HTH


Rob
 
nMath

Timestamp does not = a time field!!!!

use datetime or smalldatatime!

Timestamp is the rowversion of Oracle - it just tells us that the row has been modifed if it isn't the same. It does not represent a time value


HTH
 
You don't understand how a database stores date and time

This starts off talking about ASP but then is really in general terms and is probably the most comprehensive overview of Dates and Times!


==========================
Date is a way to show you care
Time is a great healer
DateTime is just damn confusing

Tim
 
SQL doesn't actually store the datetime data in any perticuler format. It simply depends on what the default format is when you pull it out. You have a couple of options to change it. You can either change the collation type for the database, which is kind of overkill; or you can convert the data when doing your select statement.

If you only need to view the time and not the date then you'll want to convert to type 114. If you need the date as well, use type 120.
Code:
select convert(varchar(12), getdate(), 114)
/*returns 17:29:53:910 (hh:mm:ss:mmm)*/
select convert(varchar(19), getdate(), 120)
/*returns 2004-12-09 17:30:54 (YYYY-MM-DD hh:mm:ss)*/

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Thanks so much everybody! The convert in SQL did the trick!! Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top