Jump to content

Set up the time with the correct date format


mark107

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.

 

Link to comment
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
}

  

Link to comment
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?

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.