mark107 Posted November 28, 2019 Share Posted November 28, 2019 Hi all, I am working on my PHP script to set up the date with the time for the autoresponder so I can send out the emails at the specific time. I need some help with set up the correct day date with the time, because on my code when I have two different times `06:00` and `20:00`, as both of them will show the time with the current day date, e.g: 28-11-2019. I find that my code have set up the date as incorrect because the time I have `06:00` which it should have set up with the next day date, e.g 29-11-2019 instead of 28-11-2019 and the time `20:00` should set up with the current day date as my current time is `15:26pm` right now. Output for `$autoresponder_date`: 2019-11-25 06:00 2019-11-25 20:00 Output for `$get_time`: 06:00 20:00 Here is the code: $auto_responders = $link->prepare('SELECT * FROM autoresponder WHERE campaign = ? ORDER BY id ASC'); $auto_responders->execute([$campaign]); $auto_responders->setFetchMode(PDO::FETCH_ASSOC); $auto_responders = $auto_responders->fetch(PDO::FETCH_ASSOC); $get_time = $auto_responders['send_time']; if ($get_time >= strtotime('00:00')) { $autoresponder_date = date('Y-m-d', strtotime($get_time . ' +1 day')); } else { $autoresponder_date = date('Y-m-d', strtotime($get_time)); } $send_time = $autoresponder_date . ' '. date('H:i ', strtotime($get_time)); Can you please show me an example how I can set up the day date for the time `06:00` and `20:00` as if I have the time is `06:00` then check if the time have passed before I could do anything to send the email and it is the same for the time `20:00:00`? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/ Share on other sites More sharing options...
gw1500se Posted November 28, 2019 Share Posted November 28, 2019 If I understand correctly, you need to see if the hour has gone past and if so increment the date. Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571964 Share on other sites More sharing options...
mark107 Posted November 28, 2019 Author Share Posted November 28, 2019 3 minutes ago, gw1500se said: If I understand correctly, you need to see if the hour has gone past and if so increment the date. Yes this is what I am trying to do. I want to see if the hour has gone past and increment the date. How I can do that? Do I have to use something like this? if (date('H') > $get_time) { //let do something } Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571965 Share on other sites More sharing options...
gw1500se Posted November 28, 2019 Share Posted November 28, 2019 (edited) Convert the date string to a time data type then compare: if(strtotime($test_date) < strtotime("now")) { $new_date=strtotime(&test_date. "+ 1 day"); } // format $new_date however you need Edited November 28, 2019 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571966 Share on other sites More sharing options...
mark107 Posted November 28, 2019 Author Share Posted November 28, 2019 9 minutes ago, gw1500se said: Convert the date string to a time data type then compare: if(strtotime($test_date) < strtotime("now")) { $new_date=strtotime(&test_date. "+ 1 day"); } // format $new_date however you need Thank you very much for this, but when I try this: if(strtotime($get_time) < strtotime("now")) { $autoresponder_date = strtotime($get_time. "+ 1 day"); } echo $autoresponder_date; I am getting this: 1575042480 Any idea how i can convert it to date with the time? Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571967 Share on other sites More sharing options...
gw1500se Posted November 28, 2019 Share Posted November 28, 2019 Use the date function to convert it to the needed formatted string. Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571968 Share on other sites More sharing options...
mark107 Posted November 28, 2019 Author Share Posted November 28, 2019 2 hours ago, gw1500se said: Use the date function to convert it to the needed formatted string. Thank you, I can see it is working great thanks. Quote Link to comment https://forums.phpfreaks.com/topic/309590-set-up-the-time-with-the-correct-date-format/#findComment-1571975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.