wmguk Posted February 18, 2009 Share Posted February 18, 2009 Hi, I've got a db, and people sign up. Basically when they sign up there is reg_date timestamp... part of my script is show the sign ups today, however on a monday I need to see who signed up after 5pm on friday, during saturday and during sunday... ive got a qry running, and its WHERE reg_date LIKE '<?php echo $todate; ?>%' and im using $tod = date('w') if ($tod == '1') { //if day is monday show today, yesterday and day before //HELP PLEASE } else { $todate = date('Y-m-d'); } I dont know how to say show today, yesterday and the previous day..... could someone point me in the right direction please? Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/ Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 How is the timestamp stored in the DB? As an INT as a mysql Date/Time do you store the time or just the date? Let us know how it is stored in the DB and we can help you. Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765430 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 ah sorry - its 2009-02-15 04:16:27 datetime Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765433 Share on other sites More sharing options...
premiso Posted February 18, 2009 Share Posted February 18, 2009 [php}$to_date = date('Y-m-d h:i:s'); $before_date = "2009-02-13 17:00:00"; $sql = "SELECT * FROM tabl_name WHERE reg_date BETWEEN '{$before_date}' AND '{$to_date}'"; That should get you on the right track. You may want to look into strtotime if you want to dynamically do this. Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765441 Share on other sites More sharing options...
The Little Guy Posted February 18, 2009 Share Posted February 18, 2009 Something like this: This MUST be ran on Monday for an accurate count $to_date = date('Y-m-d h:i:s',strtotime('now -3 days 5pm')); $sql = "SELECT * FROM tabl_name WHERE reg_date BETWEEN '{$before_date}' AND 'NOW()'"; Otherwise I did get this to work: $to_date = date('Y-m-d h:i:s',strtotime('previous monday -3 days 5pm')); $sql = "SELECT * FROM tabl_name WHERE reg_date BETWEEN '{$before_date}' AND 'NOW()'"; Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765452 Share on other sites More sharing options...
gizmola Posted February 18, 2009 Share Posted February 18, 2009 I should probably add this to my signature http://www.gizmola.com/blog/archives/51-Exploring-Mysql-CURDATE-and-NOW.-The-same-but-different..html Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765469 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 Hey guys, Thanks for all the suggestions, I've now got... $tod = date('w') if ($tod == '1') { $todate = date('Y-m-d h:i:s',strtotime('now -3 days 5pm')); } else { $todate = date('Y-m-d'); } looks like it should work, as its basically if $tod is monday, show last 3 days from 5pm, if its not monday show todays subscriptions... i'm guessing the only way to get to test it is to wait till monday lol... Thanks for all the help!!! Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765560 Share on other sites More sharing options...
The Little Guy Posted February 18, 2009 Share Posted February 18, 2009 Try this to see if it gets you what you want: $tod = date('w') if ($tod == '1') { $todate = date('Y-m-d h:i:s',strtotime('previous monday -3 days 5pm')); } else { $todate = date('Y-m-d'); } Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765609 Share on other sites More sharing options...
wmguk Posted February 18, 2009 Author Share Posted February 18, 2009 bingo! Thanks guys.. Link to comment https://forums.phpfreaks.com/topic/145786-solved-help-with-today/#findComment-765624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.