-2

I am using the following code to show the expiration date of my coupon;

 <?php _e('Expiration Date:','wpestate'); echo esc_html($expiration_date); ?> 

But, it is showing in following unreadable format;

Expiration Date:1491955200

Therefore how to convert it to readable format like;

Expiration date : 2017-04-30

0

The "unreadable format" you have posted is known as a UNIX timestamp. It is the number of seconds from January 1, 1970, to the date represented.

Using a handy online tool, you can quickly see what that timestamp equates to if needed: http://www.unixtimestamp.com/index.php

In order to reformat this timestamp, in your case YYYY-MM-DD, you will need to reference the PHP date format parameters: http://php.net/manual/en/function.date.php

For your example, you would want 'Y-m-d'. This assumes you want leading zeros on month and day.

Y = A full numeric representation of a year, 4 digits m = Numeric representation of a month, with leading zeros d = Day of the month, 2 digits with leading zeros

0

Thanks anyway, I managed to fixed the problem by following code;

<?php $expiration_date = get_post_meta($post->ID, 'expiration_date', true); ?>
<?php _e('Expiration Date : ','wpestate'); echo esc_html($expiration_date); ?>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.