WordPress.org

Forums

Verve Meta Boxes
[resolved] Date Output (6 posts)

  1. nimaha
    Member
    Posted 4 years ago #

    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!

  2. avenueverve
    Member
    Plugin Author

    Posted 4 years ago #

    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));?>

  3. nimaha
    Member
    Posted 4 years ago #

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

  4. nimaha
    Member
    Posted 4 years ago #

    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!

  5. avenueverve
    Member
    Plugin Author

    Posted 4 years ago #

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

  6. nimaha
    Member
    Posted 4 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic