3

In my form I have selecting date with datetimepicker which i'm using only date picker.

I need to get the selected date value to do some calculation in php through ajax.
Here is my code but the result shows date starting 01/01/1970 !!

 public function getmydateHTML() {
     $jinput = JFactory::getApplication()->input;
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);         
     $dt = $jinput->get ('dvalue');         
     $date = $jinput->get ('selectedate');
     $sdt = strtotime($date);
     $newdate = strtotime("+$dt day", $sdt);
     echo   date('d/m/Y', $newdate);      
    exit;  
}

How can I get correct selected date value?

  • 1
    you need to look at the format that your datetimepicker is submitting to your script. The default is probably yyyy-mm-dd. Be sure your script is allowing for the date format being returned or else your strtotime is going to return an improper value. – Terry Carter May 18 '16 at 22:22
  • @allogos It would be best if you included exactly what values you are receiving for $dt and $date only then can we work forward and help resolve this old question. Remember, even if this is no longer an issue for you, this site intends to help future researchers -- please help to progress this page to a resolution. – mickmackusa Jun 10 '18 at 12:31
  • @allogos please provide the necessary details to progress this abandoned page to a resolution. – mickmackusa Feb 2 at 12:28
1

Try to change it to:

"+$dt days"

Also, I may be wrong but, I believe you must provide dates in correct order as if dates diff is <0 then it would return 0 which corresponds to 01/01/1970

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.