Reply
How to insert current time in MySQL?
Old 01-07-2008, 12:13 AM How to insert current time in MySQL?
babyboy808's Avatar
Average Talker

Posts: 16
Hi,

What is the correct format for inserting the current time into MySQL?

Basically I want a 24 hour time to be stored in the db and when outputted through php I get something like: 13:46.

thanks in advance,
Keith
__________________
Keith
www.eirestudio.net
babyboy808 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 01-07-2008, 06:40 AM Re: How to insert current time in MySQL?
Extreme Talker

Posts: 214
Location: United States
Use TIME as your field type, and use the MySQL NOW() function when inserting.

It will store the time with seconds included, such as 13:46:23, so if you don't want the seconds when you retrieve it from the database, you'll have cut off the seconds and the second colon with PHP's substr() or something.

There are also other ways to store times in MySQL, such as DATETIME, TIMESTAMP or an INT which contains the Unix timestamp. The TIME field uses the least amount of storage space out of all the options, but remember that it doesn't store any information about the date.
frost is offline
Reply With Quote
View Public Profile
 
Old 01-08-2008, 10:49 PM Re: How to insert current time in MySQL?
babyboy808's Avatar
Average Talker

Posts: 16
Thanks alot frost for your in depth response, I appreciate you taking the time to help

Keith
__________________
Keith
www.eirestudio.net
babyboy808 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to insert current time in MySQL?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11168 seconds with 13 queries