Page 1 of 1

Inserting a timestamp into a mySQL Database?

Posted: Fri Nov 29, 2002 12:43 am
by Slyvampy
Having another issue, if anyone can help by telling me what I have done wrong.

I keep getting invalid dates in my database, it puts in the date as 00000000000000. :x

The code looks like this:

Code: Select all

<?php
$takings_date_timestamp = mktime(0,0,0,$takings_date_month,$takings_date_day,$takings_date_year);
?>
And the sql query looks like this:

Code: Select all

<?php
$returned = mysql_query("INSERT INTO peppersbars_daily_takings  VALUES ("$takings_date_timestamp", "$formatted_amount_taken")", $connection) or die("Addition Failed, please try again later");
?>
However after I realised it was not working I outputted the variable $takings_date_timestamp and instead of getting the result I wanted to put into my database, I got 1038528000. Can anyone explain this ? yet I did a conversion on it :

Code: Select all

<?php
$takings_date_display = date("l jS F, Y", $takings_date_timestamp);
?>
And that works fine, i get the date : Friday 29th November, 2002 :roll:

Well if anyone can help would appricate it.

Cheers,

SteJ. :?

Posted: Fri Nov 29, 2002 1:17 am
by volka
http://www.php.net/manual/en/function.m ... ote]mktime -- Get UNIX timestamp for a date
...
Returns the Unix timestamp corresponding to the arguments given. This timestamp is a long integer containing the number of seconds between the Unix Epoch (January 1 1970) and the time specified. [/quote]