Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Use custom meta key in strtotime WordPress

  • SOLVED

I have a piece of code that does two different things depending on whether it is before a certain date or not. Like so:


<?php
$end_date = strtotime('12:00am June 27, 2011' );
$now = time();
if ($end_date < $now) {

//do something

} else {

//do something else

} ?>


I want to replace part of the date with a string from a custom meta key, specifically: June 27, 2011 but leaving the 12:00am part. Or I suppose I could just lose the 12.00am part altogether.

So the outcome will be something like this... with the exception that it works.


<?php
$dbt_release = get_post_meta($post->ID, 'dbt_release', true);
$end_date = strtotime('12:00am $dbt_release' );
$now = time();
if ($end_date < $now) {

//do something

} else {

//do something else

} ?>


Thoughts?

Answers (2)

2011-03-30

John Cotton answers:

Hi James

If you meta data is in the format you mention, then this would work:

$end_date = strtotime( $dbt_release . ' T1200' );


John

UPDATE Lew - you're right, it should be


$end_date = strtotime( $dbt_release . ' T0000' );


for 12am. :)

2011-03-30

Lew Ayotte answers:

Yeah,

What you have would work, but you have the variable inside of single quotes, which I believe causes PHP to read it as just a regular string...

What John said should work, but this would work too:

$end_date = strtotime( '12:00am ' . $dbt_release );

or

$end_date = strtotime( "12:00am $dbt_release" );

Lew


Lew Ayotte comments:

Actually, I think T1200 is 12PM, not 12AM... T0 (I think)...