Click to See Complete Forum and Search --> : Date Problem
imran7706
09-23-2006, 03:29 AM
Hello all
I am using this code to insert the current date in My SQL but I am not getting the correct result Hope my friends would help me here
$A = getdate();
$Today = mktime(0,0,0,$A['mon'], $A['mday']+15, $A['year']);Thanks in advance
ronverdonk
09-23-2006, 10:48 AM
What is the result (date format e.g. yyyy-mm-dd) you want to store in MYSql?
And why not use MySql functions to accomplish that?
Ronald :cool:
imran7706
09-23-2006, 11:53 AM
What is the result (date format e.g. yyyy-mm-dd) you want to store in MYSql?
And why not use MySql functions to accomplish that?
Ronald :cool:
I am not concerned about the result format the thing is I am getting the wrong date when I try to retrive date here is the full code hope this helps u understand my situation any help or suggestion is appreciated please
$A = getdate();
$Today = mktime(0,0,0,$A['mon'], $A['mday'], $A['year']);
$SQL="insert into tourbookings values('', '".$_REQUEST[tourcode]."', '".$_REQUEST[email]."', '".$_REQUEST[phone]."', '".$_REQUEST[adults]."', '".$_REQUEST[childasadult]."', '".$_REQUEST[children]."', '".$_REQUEST[room]."', '".$_REQUEST[singlesuplement]."', '".$_REQUEST[insurance]."', '".$_REQUEST[airporttaxadult]."', '".$_REQUEST[airporttaxchild]."', '".$_REQUEST[departureairport]."', '".$_REQUEST[disc_adults]."', '".$_REQUEST[disc_childasadult]."', '".$_REQUEST[disc_children]."', '".$_REQUEST[grand_tot]."', '".$Today."', 0)";
NogDog
09-23-2006, 12:50 PM
$Today = date('Y-m-d H:i:s', mktime(0,0,0,$A['mon'], $A['mday'], $A['year']));
imran7706
09-23-2006, 01:00 PM
$Today = date('Y-m-d H:i:s', mktime(0,0,0,$A['mon'], $A['mday'], $A['year']));
when I insert this code I get this date Wed Dec 12, 1969
NogDog
09-23-2006, 01:07 PM
I just realized that you were using getdate() to populate $A (I was thinking they were form values or such). Instead of all that, just do:
$Today = date('Y-m-d H:i:s');
Or simpler yet, just let MySQL do the work by using its NOW() function:
$SQL="insert into tourbookings values('', '".$_REQUEST[tourcode]."', '".$_REQUEST[email]."', '".$_REQUEST[phone]."', '".$_REQUEST[adults]."', '".$_REQUEST[childasadult]."', '".$_REQUEST[children]."', '".$_REQUEST[room]."', '".$_REQUEST[singlesuplement]."', '".$_REQUEST[insurance]."', '".$_REQUEST[airporttaxadult]."', '".$_REQUEST[airporttaxchild]."', '".$_REQUEST[departureairport]."', '".$_REQUEST[disc_adults]."', '".$_REQUEST[disc_childasadult]."', '".$_REQUEST[disc_children]."', '".$_REQUEST[grand_tot]."', NOW(), 0)";
imran7706
09-23-2006, 01:16 PM
In both cases I am getting Wed Dec 12, 1969 this date
Thanks for the concern
NogDog
09-23-2006, 03:01 PM
In both cases I am getting Wed Dec 12, 1969 this date
Thanks for the concern
Are you sure you have all the values in your query in the right sequence? (It's safer to explicitly list the field names and then give the corresponding values list in your query, rather than trusting that the database has the table's fields in the order you think they are.)
On the off chance that there's something wrong with your system clock, you could try a quick test with something like:
echo "date('Y-m-d H:i:s');