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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.