Link to home
Start Free TrialLog in
Avatar of eNarc
eNarcFlag for United Kingdom of Great Britain and Northern Ireland

asked on

get results between a php timestamp 1206858612

hi is there anyway of getting results from mysql from a php timestamp? 1206858612
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

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 );
ASKER CERTIFIED SOLUTION
Avatar of Rik-Legger
Rik-Legger
Flag of undefined image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pius_babbun
pius_babbun

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

@eNarc

From my experience, the only time I use timestamp is when getting the difference between two dates
i.e.
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
Avatar of eNarc

ASKER

Perfect