Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom table with a DATETIME column. I have a function to add records; I would like to add an $expires argument to this function which can hold a unix timestamp noting when the record should expire. I would like to use $wpdb->insert() to populate this column. So far I've been unable to find a WordPress convenience function to massage the timestamp into 'YYYY-MM-DD HH:MM:SS' format. Is there such a builtin, or should I just use $wpdb->prepare(), or possibly a third option?

share|improve this question
add comment

1 Answer

Couldn't you just use PHP's date() function?

$prepared_date = date( 'Y-m-d H:i:s', $expires );
share|improve this answer
    
That should do the formatting job and $wpdb->prepare() is the preferred method to do that in wordpress. –  hakre Aug 24 '10 at 14:42
    
I'm using that currently (well, strftime()) but I thought I was just missing a WordPress-delivered function. Seems like something that would exist, to prevent having the datetime format in multiple places. –  Annika Backstrom Aug 24 '10 at 15:30
    
Yeah, they have a function for getting that format for the current time, but not from a specific timestamp: phpxref.ftwr.co.uk/wordpress/wp-includes/… –  John P Bloch Aug 24 '10 at 15:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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