I’m using the date picker field to insert the date that my webinars are recorded and have them appear in the members area in the order they are created.
I have set the save format as yymmdd and the display format as ddmmyy, but the date appears on the page as “Thursday 1st January, 1970” regardless of what date I select from the date picker calendar.
I’ve updated WP to version 3.6 and updated custom fields to version 4.2.0.
Any help is much appreciated.
Hi @sallywp
What code are you using to display the date field data?
I am having the same problem as well.
I’m using the following code in my theme functions file
function datepicker_to_unix( $date ){
$dateparts = explode('/', $date);
$unixtimestamp = strtotime(date('d.m.Y', strtotime($dateparts[1].'/'.$dateparts[2].'/'.$dateparts[0])));
return $unixtimestamp;
}
And then the following in my template file
<?php $date = get_field('field_name'); echo date('F d, Y', datepicker_to_unix($date )); ?>
The result outputs: January 01, 1970
Hi @kikimarie1234
Have you debugged the variables in each step?
Can you post the results?
I’m having this same issue as well. Have tried changing return values as well as every method of parsing the date field data in php, but it always either returns empty of with January 01, 1970. The dates are correct in the WP database, so something must be happening on the return trip to the browser.
Any info here? Noticing this on my end as well. The date field is blank in the DB, but the browser shows as January 1, 1970.
I’m having the same issue when using the date field in a repeater (the repeater is the subfield of a group).
When I use the code $date = get_sub_field('date');
and echo the variable, the string returned matches the data entry in the database (each date is different). When I convert the date using methods above such as <?php echo date("F j, Y", strtotime($date)); ?>
, the strtotime is not working and Jan 1, 1970
is always returned.
In contrast, when I use the DateTime method mentioned above, only the current day’s date is returned.
Is this a bug, should DateTime be avoided in repeaters?