get results between a php timestamp 1206858612

hi is there anyway of getting results from mysql from a php timestamp? 1206858612
Who is Participating?
Rik-LeggerConnect With a Mentor Commented:
It depends on how the date is stored in your database and what the range of the date is.
But normally you can do it like so:

SELECT * FROM `dt` WHERE timestamp between 1206858612 and 1207858612

Open in new window

Beverley PortlockCommented:
Well you can convert the timestamp to YYYY-MM-DD format and use that in MySQL queries. Is that what you are looking for?

$mySqlDate = date("Y-m-d", 1206858612 );

or more generally....

$timestamp = 1206858612;
...... other code......
$mySqlDate = date("Y-m-d", $timestamp );
I just got this from the PHP manual...

check if it is helpful to you
$str = 'Not Good';

// previous to PHP 5.1.0 you would compare with -1, instead of false
if (($timestamp = strtotime($str)) === false) {
    echo "The string ($str) is bogus";
} else {
    echo "$str == " . date('l dS \o\f F Y h:i:s A', $timestamp);

Open in new window


From my experience, the only time I use timestamp is when getting the difference between two dates
convert date 1 & date 2 to timestamp
difference = date2 - date1
after which its comverted back using date()

When using MySQL, I always have the date in the format YYYY-MM-DD HH:MM:SS

I would go with bportlock's suggestion and convert to this format using the date() function
$mySqlDate = date("Y-m-d", 1206858612 );
then use that in your query
eNarcAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.