Hi,
I've always had a bit of trouble figuring out how to use a php function within a query. Hopefully someone can help out.
This is what I am current trying to do
select * from items where strtotime(time) < time()
Is this allowed?
If not can anyone help me format this in a way that is.
Thanks!
--SL
you're gonna wanna only use mysql functions inside your query
strtotime is a php function
simply to a strtotime outside on a variable, the put that variable inside the query
Hello,
Unfortunately, I can't do this since time is a field in my table.
Is there any way in Mysql to compare a datetime field to the current time?
Thanks,
Hi, what kind of time you use ? Time, Date, DateTime or Unixstamp ?
If is just Time try this:
$now=date("H:i:s"); select * from items where timefieldname < $now
Thanks for your reply.
Unfortunately it is a datetime field. 2003-05-28 22:52:57
Do you have any ideas for this?
Yes, is the same if you check also for date.
To check only for time try:
$now=date("H:i:s"); select * from items where EXTRACT(HOUR_SECOND FROM timefieldname) < $now
but is easiest if you split in two field one time, one date...
To get the current date / date for a timestamp... www.php.net/date
<?php mysql_query ("SELECT * FROM items WHERE my_time_field < " . date ("Y-m-d h:i:s") . " "); ?>
Great! Thanks for your help. I also found another solution.
select * from items where time < now();