If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to insert the date and time into a data base while doing routine inserts.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-07-09, 14:20
tommytx tommytx is offline
Registered User
 
Join Date: Dec 2004
Posts: 2
How to insert the date and time into a data base while doing routine inserts.

I have several fields set up in mysql data base and one of them is set to take date data. However I cannot figure how to format it so the date field will accept it.

$mydate = date("F j, Y");

$mytime = date("g:i a");

$query = "INSERT INTO confirm (id, amtitle, code, mydate, mytime) VALUES ('$userid', '$amtitle', '$code', '$mydate', '$mytime')";

I tried something like this, but it would not accept it and came back with a format like 0000-00-00
So i changed my date field to characters and it will then hold the date, but not being a date field it cannot be manipulated as a date field of course.
Reply With Quote
  #2 (permalink)  
Old 06-07-09, 15:25
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,260
well first off i'd stroe the date and time as a single column
I'd then make sure the format of the date/time is set correctly for the MySQL engine in the PHP script

IIRC the datatype in the MySQL is datetime NOT Timestamp
the date time format is iso date ie YYYY/MM/dd @ HH:MMS
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 06-07-09, 19:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
INSERT 
  INTO confirm 
     ( id
     , amtitle
     , code
     , mydatetime ) 
VALUES 
     ( '$userid'
     , '$amtitle'
     , '$code'
     , CURRENT_TIMESTAMP )
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

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