Home » Wordpress » How to seperate day from acf datepicker

How to seperate day from acf datepicker

Posted by: admin February 26, 2018 Leave a comment

Questions:

I have advanced custom field date picker form which I need to separate the day (monday,tuesday etc).Is this possible ,if yes anyone please tell me how?

  <p><strong>15-2-2014 Saturday</strong></p>

this is my html code

Answers:

Try this. If the date format is yymmdd, then the following works.

$date = get_field('date');


$y = substr($date, 0, 4); //Year
$m = substr($date, 4, 2); //Month
$d = substr($date, 6, 2); //date

Find the ACF doc: ACF Datepicker

Questions:
Answers:

If You are using PHP then use below code:-

echo $dt = date("d",strtotime("15-2-2014 Saturday"));

this will give You 15 as output.

Questions:
Answers:
$string  = "<p><strong>15-2-2014 Saturday</strong></p>";
$string = explode(" ",preg_replace('~<[^>]+>~','',$string));
$day = $string[1];

edit:

If you are using get_field() to get the date and it is in the format you showed, then it’s still a string. You’d do this:

$string  = get_field('date');
$string = explode(" ",preg_replace('~<[^>]+>~','',$string));
$day = $string[1];

the preg_replace may or may not be necessary depending on whether or not those html tags are really there, but it will work regardless. But if they aren’t there, then it can be simplified to

$string  = get_field('date');
$string = explode(" ",$string);
$day = $string[1];