Solved

get results between a php timestamp 1206858612

Posted on 2011-03-15
5
253 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
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 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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