PHP Front To Back [Part 8] – Dates & Timestamps | VPS and VPN
Web Hosting

PHP Front To Back [Part 8] – Dates & Timestamps



In this video we will look at the PHP date() function as well as mktime() and strtotime() to create dates and timestamps from strings CODE: Code for this video …

33 thoughts on “PHP Front To Back [Part 8] – Dates & Timestamps

  1. date_default_timezone_set() did not work for me for some reason, and I had to use:
    $now = new DateTime();
    $now->setTimezone(new DateTimeZone('America/Vancouver'));
    echo $now-> format('h:i:sa');
    to change the correct time zone.

    According to stackoverflow, servers should be set to UTC, and you should not be looking to change the default. Instead, what you want to do is create a DateTime object based on the time, then convert it to the timezone you want, and display.
    https://stackoverflow.com/questions/11911852/changing-php-default-timezone-not-working

  2. the tutorial is awesome, but f*#@ american dating system where they type M/D/Y and not LOGICAL D/M/Y. I was thinking about 10 minutes why my birthday date isn't correct when there were no mistakes in my code…

  3. unfortunately for me, it's returning the wrong day… i went into php.ini and changed my timezone [date.timezone = "America/New_York"] but that did not work. there must be something conflicting…

  4. Brad, you are one of the coolest people ever! I deeply appreciate what you do for us, even though we are just a strangers behind the screens all over the planet! With your tutorials you helped me A LOT, so THANK YOU VERY, VERY MUCH! Be healthy and happy and keep rockin'! I'll take the risk to appear like a gay, and just say that I love you! 🙂 I am broke now, but I promise you, the moment I get my first payment as developer, witch I believe will be soon, I will also support you, by buying some paid tutorial of yours! Bless you!

  5. First of all thanks Brad, I thoroughly enjoy learning with Traversy Media… Kudos…

    I'm having an issue with string to time, here we go:

    $timestamp2 = strtotime('7:00pm March 22 2016');
    echo date('m/d/y h:i:s a, $timestamp2');

    03/27/18 02:11:09 pm, $311103Africa/Nairobi0931pm03p2

    I am also getting the time zone in a unreadable format:

    $311103Africa/Nairobi0931pm03p2

    This is certainly caused by the default time zone I've set…

    How do I get rid of it?

    Thanks…

  6. Hey brad, awesome teaching and I've already become a fan of yours. I'll definitely buy your course once I get a job to show my gratitude. Thanks a lot and god bless you.

  7. Good video but way too basic. I am struggling to find a video that simply compares a format. I am opening a file which I need to read the date which has been given. All I need to do is display the date and provide an error message if it does not match. I dont know why it is so difficult, all I have tried so far is:

    $dummyDate = ''31/2/2016' ; //Date which was given from the file//

    if(date('d/m/Y', strtotime($dummyDate) == $dummyDate){
    echo("<p>Module date: " . $dummyDate . "</p>");
    }else{
    echo("<p>Module date: " . $dummyDate . " Date invalid </p>"
    }

    This should be coming back as true because the date is in valid format, I dont know why It is coming back as false.

Leave a Reply

Your email address will not be published. Required fields are marked *