Skip to content

Instantly share code, notes, and snippets.

@badah
Last active August 29, 2015 14:09
Show Gist options
  • Save badah/fb9638029191e5ef40ad to your computer and use it in GitHub Desktop.
Save badah/fb9638029191e5ef40ad to your computer and use it in GitHub Desktop.
Wordpress: get date from date custom field
<?php
//PHP > 5.3
$date = DateTime::createFromFormat('Ymd', get_field('date'));
echo $date->format('d/m');
//PHP < 5.3
$date = get_field('date');
// extract d/m
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
// format date (23/11/1988)
echo date('d/m', $time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment