Inserting a timestamp into a mySQL Database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Slyvampy
Forum Newbie
Posts: 23
Joined: Thu Nov 28, 2002 2:03 am
Location: Yorkshire, England
Contact:

Inserting a timestamp into a mySQL Database?

Post 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. :?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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]
Post Reply