Jump to content
Sign in to follow this  
mark107

Set up the time with the correct date format

Recommended Posts

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.

 

Share this post


Link to post
Share on other sites

If I understand correctly, you need to see if the hour has gone past and if so increment the date.

Share this post


Link to post
Share on other sites
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
}

  

Share this post


Link to post
Share on other sites

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 by gw1500se

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

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