Solved

get results between a php timestamp 1206858612

Posted on 2011-03-15
5
248 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
5 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
@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
Comment Utility
Perfect
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Save signature to file 7 44
Creating a slider 12 32
Page showing diff display 4 19
Phone Dialer 5 35
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now