Store date without all the info

This topic is: not resolved

This topic contains 5 replies, has 3 voices, and was last updated by  logikal16 3 years, 6 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #159732

    logikal16
    Member

    @peroyomas – By default, a date column will always output the full MySQL date, e.g. "2009-11-13 14:28:00".

    However, Display Helpers allow you to "intercept" the value and change it before it gets displayed.

    === Create a display helper: "year_only" ===
    <pre><?php echo date("Y", strtotime($value)); ?></pre>

    === Adjust your magic tag ===
    <pre>{@your_date_column, year_only}</pre>

    #159733

    peroyomas
    Member

    The problem is that I want to display in a list template the full date along each pod, but I don’t have the day and month of all the articles, so I want to make it look like this:

    Article 6 (01/01/2003)

    Article 5 (04/27/2003)

    Article 4 (05/2003)

    Article 3 (05/03/2003)

    Article 2 (2003)

    Article 1 (03/2003)

    #159734

    laura
    Member

    I have the exact same issue. I tried to find a solution that enables me to still use the date column, but I was unable to do so.

    You could use a text field instead, but you won’t be able to sort by date. I need to do that so I came up with an alternate solution, which is probably a bit messy, but it works.

    Instead of one field for the date, I created 3 fields (year, month, day) using column type ‘number’. Then I call my findRecords sorting by year, then month, then day:
    <pre>$pod->findRecords(‘year DESC, month DESC, day DESC’);</pre>

    I assign variable for each of those fields:
    <pre>
    $year = $pod->get_field(‘year’);
    $month = $pod->get_field(‘month’);
    $day = $pod->get_field(‘day’);
    </pre>

    Then format my date variable:
    <pre>
    if ($day == 0 AND $month == 0 AND $year) $date = date("Y", mktime(0,0,0,$month,$day,$year));
    elseif ($day == 0 AND $month AND $year) $date = date("F Y", mktime(0,0,0,$month,$day,$year));
    elseif ($day AND $month AND $year) $date = date("F, j Y", mktime(0,0,0,$month,$day,$year));
    else $date = ‘Unavailable’;
    </pre>

    If anyone has a more elegant solution, please weigh in.

    #159735

    laura
    Member

    I also applied the input helper package plain_numbers to year, month and date fields. I changed it to:
    <pre><input type="text" class="form <?php echo $coltype . ‘ ‘ . $name; ?>" value="<?php echo @number_format($value, 0, ‘,’, ”); ?>" /></pre>
    to remove the comma from the year.

    #159731

    peroyomas
    Member

    I want to use pods to store a lot of press articles. I thought of using the date column to put the date of each article, but I don’t have the exact date of each article, in many of them I only have the year, or the year and the month but not the day. I’m not sure if there’s a way to store that info appropriately and only display the specified values (if only have year, display only it instead of the whole year/month/day). May using text field for each year/month/ day be a better idea?

    #159736

    logikal16
    Member

    You can do something similar using just the date column. If you don’t know the day or month, just set it as "00". Then you can adjust your display helper accordingly.

    Ex:
    "2012-12-25 00:00:00" -> "12/25/2012"
    "2007-03-00 00:00:00" -> "03/2007"
    "2009-00-00 00:00:00" -> "2009"

    <pre>
    <?php
    // Ignore the time part of the datetime
    $date = explode(‘ ‘, $value);
    $date = $date[0];

    // Break the date apart into year, month, day
    $date = explode(‘-’, $date);

    // The day is real
    if (’00′ != $date[2])
    {
    echo $date[2] . ‘/’ . $date[1] . ‘/’ . $date[0];
    }

    // The month is real
    elseif (’00′ != $date[1])
    {
    echo $date[1] . ‘/’ . $date[0];
    }

    // The year is real
    elseif (’00′ != $date[0])
    {
    echo $date[0];
    }

    // Nothing works
    else
    {
    echo ‘Invalid date’;
    }
    ?>
    </pre>

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Wordpress Cloud Hosting