|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Quote:
Well that's true Was assuming anyone wouldn't be so stupid to use any other language *cough* *snicker*My bad ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Date/Time |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|