MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 28th, 2006, 03:07 AM
bobso bobso is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 1 bobso User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 23 sec
Reputation Power: 0
Date/Time

Hey guys!
When inserting into a MySQL date/time field, what is the syntax i use?
i know insert etc but what format
ie YYYY-MM-DD:HH-MM-SS
if you know please give a whole insert statement that would show how to insert into a date/time field (if it isnt too much trouble)
Thanks
Bobso

Reply With Quote
  #2  
Old August 28th, 2006, 06:29 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
now() <-- gives all you need... but let's explain a bit further.

First thing to consider is how you set it up in the database, obviously you like to insert this into it. You can choose date, time or datetime...

It doesn't matter which one you use you can still call todays date by now() when insterting.

mysql_query("UPDATE tsg_users SET visit_date = NOW(), visit_time = NOW(), visit_count = visit_count +1 WHERE id = $USERID");

The above is just an example from a page where I like to add the visit date, time and add +1 to the visit count when a user logs on to the site.

You can also format the date in various ways...

$date = date("Y-m-d");

Read more here : http://se.php.net/date

Reply With Quote
  #3  
Old August 28th, 2006, 07:49 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Well, bobso's initial question didn't say anything about PHP...

NOW() is definitely the best way to get the current date and time into the database...
If you want to make up a date, you could use many ways.

Myself, I usually use YYYY-MM-DD HH:MM:SS, something like:
Code:
INSERT INTO tbl VALUES ('1990-09-21 14:25:00');

There's a variety of ways, listed in MySQL's DateTime Documentation
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #4  
Old August 29th, 2006, 08:30 AM
Laban Laban is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Posts: 40 Laban User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 15 m 32 sec
Reputation Power: 4
Quote:
Originally Posted by MadCowDzz
Well, bobso's initial question didn't say anything about PHP...


Well that's true Was assuming anyone wouldn't be so stupid to use any other language *cough* *snicker*

My bad

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Date/Time


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT