skip to Main Content

I’m using the Twitter API and am rather new to it. I understand that when I use the GET tweet array [created_at] it outputs something along the lines of

Thu Aug 31 12:07:00 +0000 2017

is there a way to simply get

Thu Aug 31

in one variable and

12:07:00

in a second variable? So I can simply use just the time and date.

2

Answers


  1. You have to first convert that string into date and time formate by passing that value in date() function from php.

    Then you can get date and time from that and store that in different variables.

    Use date and time format function from php.

    <?php
    
       $dateandtime = new DateTime("Your date string getting from twitter");
       $variable1=$dateandtime->format("D M m");        
       $variable2=$dateandtime->format("H:i:s");
    
     ?>
    
    Login or Signup to reply.
  2. Another core approach to convert returned datetime in the required format

    $dateString = "Thu Aug 31 12:07:00 +0000 2017";
    //use strtotime function to get timestamp of a string date
    //returnedTimestamp=strtotime($dateString);
    $datePart=date('D M d',$returnedTimestamp);
    $timePart=date('H:i:s',$returnedTimestamp);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search