Jump to content

Archived

This topic is now archived and is closed to further replies.

redarrow

[solved]timestamp quistion

Recommended Posts

if i add the timestamp to the database and put it under date but a time stamp

what command do you use to get it in the database as the time stamp.

example

$date=date("y-m-d");
$date_know=strtotime($date);

echo $date;

Share this post


Link to post
Share on other sites
If the database field definition is DATE use date

If the database field definition is DATETIME use time stamp

Not sure if that actually answers the question ... ?

Share this post


Link to post
Share on other sites
say you want to enter in the database the date for today but you want the database to have it in the format of a time stamp how cheers.

Share this post


Link to post
Share on other sites
Do you mean a unix timestamp? A unix timestamp returns the number of secounds since Jan 1st 1970. if you want to convert a date into a unix timestamp use strtotime function:
[code=php:0]$date = "25-12-2006";

// conver the date above into unix timestamp
// which is 1167004800
$timestamp = strtotime($date);

// convert it back into a date
echo date("d - m - y", $timestamp);[/code]

or use the time() function to get the unix timestamp of now.

I use INT as the data type for storing timestamps.

Share this post


Link to post
Share on other sites
i am so confused when i turn the timestamp back i get 01-01-70 should be 15-08-06

what am i doing wrong please cheers.

[code]

<?php

$date=date("d-m-y");

//echo $date;//15-08-06

$date_know=strtotime($date);

//echo $date_know;//1438815600 is the time stamp.

$timestamp_result=date("d-m-y",$dateknow);

echo $timestamp_result;//i get this why? 01-01-70

?>
[/code]

Share this post


Link to post
Share on other sites
$timestamp_result=date("d-m-y",$dateknow);

should be:

$timestamp_result=date("d-m-y",$date_know);

Share this post


Link to post
Share on other sites
didnt see that cheers what an ?????

thank you .

one last quistion what does int stand for ?

Share this post


Link to post
Share on other sites
why dosent windows like the code got this error

Warning: date(): Windows does not support dates prior to
midnight (00:00:00), January 1, 1970


pleae tell me cheers.


[code]
<?php

//time stamp for one month foward.


$timestamp_one_month_foward="262974383";

//time currently plus time stamp for 1 month.


$date=("d-m-y")+$timestamp_one_month_foward;


// convert date into the unix timestamp


$date_timestamp=strtotime($date);


// get current date what should be 1 month foward.


$result=date("d-m-y",$date_timestamp);


echo $result;


?>
[/code]

Share this post


Link to post
Share on other sites
From the date() page of the php manual ... the answer is that Jan 1/70 is the beginning of time.

[quote]Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)[/quote]

As long as Barand and me (and a few others) stay away, that won't matter  :o

Share this post


Link to post
Share on other sites
lol that funny

does this look ok and correct  it dispalys correctl but is it a proper programming way

please and cheers.


[code]
<?php
// 1 month in front of current date.

$m=date("m")+1;

// current date.

$date=date("d-$m-y");

// current date in a time stamp

$date_timestamp=strtotime($date);

echo "<br>This is the time stamp one month foward:$date_timestamp<br>";

$result=date("d-m-y",$date_timestamp);

echo "<br>This is the readable result:$result<br>";
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.