/    Sign up×
Community /Pin to ProfileBookmark

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

[code=php]$A = getdate();
$Today = mktime(0,0,0,$A[‘mon’], $A[‘mday’]+15, $A[‘year’]);[/code]

Thanks in advance

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ronverdonkSep 23.2006 — 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 ?
Copy linkTweet thisAlerts:
@imran7706authorSep 23.2006 — 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 ?[/QUOTE]

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
[code=php]$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)";[/code]
Copy linkTweet thisAlerts:
@NogDogSep 23.2006 — [code=php]
$Today = date('Y-m-d H:i:s', mktime(0,0,0,$A['mon'], $A['mday'], $A['year']));
[/code]
Copy linkTweet thisAlerts:
@imran7706authorSep 23.2006 — [code=php]
$Today = date('Y-m-d H:i:s', mktime(0,0,0,$A['mon'], $A['mday'], $A['year']));
[/code]
[/QUOTE]

when I insert this code I get this date Wed Dec 12, 1969
Copy linkTweet thisAlerts:
@NogDogSep 23.2006 — 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:
[code=php]
$Today = date('Y-m-d H:i:s');
[/code]

Or simpler yet, just let MySQL do the work by using its NOW() function:
[code=php]
$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)";
[/code]
Copy linkTweet thisAlerts:
@imran7706authorSep 23.2006 — In both cases I am getting Wed Dec 12, 1969 this date

Thanks for the concern
Copy linkTweet thisAlerts:
@NogDogSep 23.2006 — In both cases I am getting Wed Dec 12, 1969 this date

Thanks for the concern[/QUOTE]

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:
[code=php]
echo "date('Y-m-d H:i:s');
[/code]
×

Success!

Help @imran7706 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...