Support » Plugin: Date and Time Picker Field » unable to get difference between time

  • Resolved neha

    (@glassfairy)


    i have a datetime picker with save as timestamp set to yes.

    i m trying to get the difference between the datetime set in the post andthe current datetime but i keep getting error diff() on no object..

    $date1=new DateTime();
    $format="d/m/Y H:m:s";
    $date2= get_field('expirydate');
    $date2=date_i18n($format,$date2);
    
    $date1==date_i18n($format,$date1);
    $difference = $date2->diff($date1);
    
    $timeleft=$difference->format('%d:%h:%i:%s');
    echo $timeleft;

    https://wordpress.org/plugins/acf-field-date-time-picker/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Per Søderlind

    (@pers)

    date_i18n returns a string, not a date object.

    even if i convert it to time using strtotime it doesn’t work….how do i get it to calculate the difference in time betweem date1 and date2

    plus when i echo the date2 it shows wrong date and time…not the one is set

    Plugin Author Per Søderlind

    (@pers)

    Try this (not tested):

    $date1 = new DateTime('now');
    $date2 = new DateTime();
    
    $expiredate = get_field('expirydate');
    $date2->setTimestamp($expiredate ); 
    
    $difference = $date2->diff($date1);
    
    $timeleft=$difference->format('%d:%h:%i:%s');
    echo $timeleft;
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘unable to get difference between time’ is closed to new replies.