?
Solved

get results between a php timestamp 1206858612

Posted on 2011-03-15
5
Medium Priority
?
267 Views
Last Modified: 2012-05-11
hi is there anyway of getting results from mysql from a php timestamp? 1206858612
0
Comment
Question by:eNarc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35137694
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 );
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 2000 total points
ID: 35137696
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

0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35137831
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

0
 
LVL 3

Expert Comment

by:sbickerstaff
ID: 35138098
@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
0
 
LVL 5

Author Closing Comment

by:eNarc
ID: 35139905
Perfect
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question