logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$15
Use custom meta key in strtotime

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?

This question has been answered.

James Beardmore | 03/29/11 at 8:20pm Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    03/29/11
    8:58pm
    John Cotton says:

    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. :)

    Previous versions of this answer: 03/29/11 at 8:58pm

  • avatar
    Last edited:
    03/29/11
    8:48pm
    Lew Ayotte says:

    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

    • 03/29/11 8:47pm

      Lew Ayotte says:

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

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.