• Resolved nimaha

    (@nimaha)


    I have a question surrounding the output of date and time fields.

    When you save data to a date or time field, it stores the data and outputs it as 2010-07-13 17:00:00, In the custom meta field, I had selected 05, 00, and PM from the time drop downs. PM doesn’t output anywhere. It seems to just tell the time to go to 17 instead of 5.

    I got the same output when I put a date in the date field (2010-07-13 00:00:00).

    So basically, it doesn’t matter if it’s a date or time field, it outputs the same data and isn’t very user friendly.

    Is this expected behavior? How can it be fixed?

    And by the way, I really appreciate this plugin! Combined with Custom Post Types UI, it really creates a nice user interface and speeds up my work. Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author avenueverve

    (@avenueverve)

    Hi nimaha,

    The format the date is stored in the database is a standard format, and it is much better for data to be stored in this way. Makes possible to compare dates, etc.

    What you are looking for is the way to format dates. This can be done with the php date function: http://php.net/manual/en/function.date.php

    so for example if you want to see June 25, 2010 @ 5:30 PM, you would do something like this:
    `<?php echo date(“F j Y @ g:i A”,strtotime($your_custom_date_field_value_here));?>

    Thread Starter nimaha

    (@nimaha)

    <–Slapping my forehead. Thanks, my brain just had a bad moment there.

    Thread Starter nimaha

    (@nimaha)

    Well, I’m not as smart as I thought I was. The date format for storing and outputting makes perfect sense as I’ve used that plenty, but I’m not sure about the strtotime function.

    my date value is date_1 so I have this:

    `<?php echo date(“F j Y @ g:i A”,strtotime($date_1));?>

    But that’s returning the starting value of January 1 1970 @ 12:00 AM. The date I am expecting is September 4, 2010 @ 5:00 PM which is what the database is storing.

    I’ve tried reading up on this but it’s not clicking. Do you have any advice on that? Thanks!

    Plugin Author avenueverve

    (@avenueverve)

    well first you need to retrieve your value using the wordpress function get_post_custom(), then use it in the code to format the date…

    Thread Starter nimaha

    (@nimaha)

    Okay, I see. I have it outputting the way I want now. For anyone who may benefit in the future, here’s what I did:

    <?php echo date("n/j",strtotime(get_post_meta($post->ID, 'date_1', true)));?>

    Thanks for your input and work on this plugin!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Verve Meta Boxes] Date Output’ is closed to new replies.