FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


SQL QUERY for yesterday's Record





AOP Web Development
Hello everyone, could anyone can give me a single queries by getting all the yesterday's record? i was trying to work by displaying the yesterdays record, the format in saving my data is DATETIME.

Do you guys have any ideas? thanks advance for the help.
rvec
Code:
$yesterday = date(Y-h-d G:i:s,mktime(0, 0, 0, date("m")  , date("d")-1, date("Y")));
$today = date(Y-h-d G:i:s,mktime(0, 0, 0, date("m")  , date("d"), date("Y")));

$query = "SELECT * FROM thetablename WHERE time_tag >= $yesterday and time_tag < $today";

and then query that Smile
AOP Web Development
Well i would like to ask by using date does it depend on the local time or it returns the unix time ? such the greenwich time.?
AftershockVibe
Note that that will give you yesterdays posts from the perspective of the server (probably on UTC time).
If you're in a different timezone then you'll need to add/subtract hours as necessary.

EDIT: lol, looks like you asked before I had a chance to tell you.

Cool
rvec
AOP Web Development wrote:
Well i would like to ask by using date does it depend on the local time or it returns the unix time ? such the greenwich time.?

If you want some other time you could use this:
http://nl2.php.net/date_default_timezone_set

The different possible timezones:
http://nl2.php.net/manual/en/timezones.php

Put that in front of all the scripts using the time and date functions.
For me that would be:
date_default_timezone_set ('Europe/Amsterdam')

by default it will use the server time, which you can see here:
http://www.frih.net/phpinfo.php
AftershockVibe
I do believe I just learned something. Having done my stuff in PHP 4 this stuff didn't exist before.
AOP Web Development
mm.. well what just i want is for, the greenwich time... that since we are in different time format.
rvec
AOP Web Development wrote:
mm.. well what just i want is for, the greenwich time... that since we are in different time format.
then use 'Europe/London'
AOP Web Development
Thanks for your help, but i found this single query solve my probs......... i never encounter this before, but it seems it's working....


Code:


$sql = "SELECT * FROM TABLE WHERE TO_DAYS(sDate) = TO_DAYS(NOW() - INTERVAL 1 DAY)";"

# i set the date as DATE TIME FORMAT


Related topics
HTTP AUTH with PHP and mySQL
phpBB transfering
SQL to XML converter
sql with phpmyadmin
MySql to SQL
SQL query problem
paging sql result
mySQL Query/PHP code - get the highest value...
Debug my SQL query please
SQL: SELECTing order ?
WIN 100FRIH$ - ITS EASY
Error while creating the SQL table pls help
Strange Problem in PHP-MYSQL
Error writing to Temp SQL files
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.