Jump to content

PHP & SQL time compare


shoombooltala

Recommended Posts

are you storing it as a DATE datatype? if so, just do something like this:
[code]
<?php
$yesterday = date('Y-m-d', strtotime('yesterday')); // SQL format for yesterday (24 hours ago)
$sql = mysql_query("SELECT * FROM table WHERE myDate >= '$yesterday'");
?>
[/code]

hope this helps

actually, after thinking about it, just use SQL to do it more cleanly:
[code]
SELECT * FROM table WHERE myDate >= DATE_SUB(CURDATE(), INTERVAL 24 HOURS);
[/code]
Link to comment
https://forums.phpfreaks.com/topic/22096-php-sql-time-compare/#findComment-98891
Share on other sites

[quote author=obsidian link=topic=109538.msg441650#msg441650 date=1159278429]
are you storing it as a DATE datatype? if so, just do something like this:
[code]
<?php
$yesterday = date('Y-m-d', strtotime('yesterday')); // SQL format for yesterday (24 hours ago)
$sql = mysql_query("SELECT * FROM table WHERE myDate >= '$yesterday'");
?>
[/code]

hope this helps
[/quote]

ok i'm trying to do this but I don't exactly understand what  strtotime('yesterday') does!!

i have a php script that gets executed every 10 mins. the point of it is to send a report only ONCE a day.

in it i need to compare today's date and time to the record in the database which holds the date and time of the last time an email was sent.

if it was yesterday then send the email, update the lasttime sent in the database to the current time so that whole day it wont send another email until tomrrow.

any ideas?
Link to comment
https://forums.phpfreaks.com/topic/22096-php-sql-time-compare/#findComment-98994
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.