Sam
Sam

Reputation: 31

Warning: date() expects parameter 2 to be long

Getting the following error:

Warning: date() expects parameter 2 to be long, string given in /home/15063/brooks/www.brooks-shopping.co.uk/public_html/wp-content/themes/sandbox/functions.php on line 546

Which points to the line:

$day = date("l, F jS", get_post_meta($post->ID, 'date_value', true));

Can someone suggest, what changes are required to the above line to resolve this please?

Upvotes: 2

Views: 2032

Answers (3)

cjds
cjds

Reputation: 8426

Date expects parameter 2 to be a long. i.e. it expects a number to be returned.

You return a string (assuming) with get_post_meta You need to convert it to a time first before you can return it (a date long)

Instead try

$day = date("l, F jS", strtotime(get_post_meta($post->ID, 'date_value', true)));

The strtotime function return an int as shown here

Upvotes: 3

anubhava
anubhava

Reputation: 785681

Cast it to int first like this:

$day = date("l, F jS", (int) get_post_meta($post->ID, 'date_value', true));

Upvotes: 0

Dr. Dan
Dr. Dan

Reputation: 2288

Assuming get_post_meta returns the time in string, try this and see if it works

$day = date("l, F jS", strtotime(get_post_meta($post->ID, 'date_value', true)));

Upvotes: 3

Related Questions