mat3osz Posted August 30, 2016 Share Posted August 30, 2016 Hi!I need some help with PHP. A few days ago I installed the plugin into Wordpress. Everything worked, but today an error occurred. Warning: date() expects parameter 2 to be long, string given in /home/wp-content/plugins/upcoming-events-lists/upcoming-events-lists.php on line 211 Line 210 and 211: $start_date = get_post_meta( $post_id, 'event-start-date', true ); echo date( 'F d, Y', $start_date ); Can somebody be so kind as to tell me what I need to change to resolve this? I need to fix this ASAP ;/ Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/302042-warning-date-expects-parameter-2-to-be-long/ Share on other sites More sharing options...
ginerjm Posted August 30, 2016 Share Posted August 30, 2016 start_date is apparently NOT an integer, ie, a time value. You need to do a strtotime() on it before trying to format it is a viewable date/time value. Quote Link to comment https://forums.phpfreaks.com/topic/302042-warning-date-expects-parameter-2-to-be-long/#findComment-1536858 Share on other sites More sharing options...
Jacques1 Posted August 30, 2016 Share Posted August 30, 2016 The date() function expects a Unix timestamp (i. e. an integer) as the second parameter. See the PHP manual. Your $start_date is appearently not a Unix timestamp. It may be a MySQL DATE which must be parsed before it can be converted. There may be a WordPress function for it. Otherwise you'll have to parse the date yourself and then reformat it. <?php const MYSQL_DATE_FORMAT = 'Y-m-d'; $input = '2016-08-30'; echo DateTime::createFromFormat(MYSQL_DATE_FORMAT, $input)->format('F d, Y'); 1 Quote Link to comment https://forums.phpfreaks.com/topic/302042-warning-date-expects-parameter-2-to-be-long/#findComment-1536859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.