Results 1 to 2 of 2

Thread: Standard Dates

  1. #1
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Standard Dates

    The last two days Ive been reading into the PHP FAQ to solve my problem with Dates, but I cant seem to find any info there or in the nettalk forums that resolve my problem. Basically I want to fetch the current date in this format Day, Month, Year and insert it into my DB then fetch the info later on and display it like Day, Month, Year. Up till now Ive used Unix Timestamps, but well I dont need the exact minute or hour for this project and the Unix Timestamp uses just that.

    Ive used the Date function to get the date, but cant insert the Variable with the date into my database. The column type is currently set at Date.

    Thanks for any help.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The column type is currently set at Date.
    That might be the problem right there. Mysql is annoying about how it auto formats some things. Just change it to mediumtext, or something along those lines. (An int setting could work, but then it defaults to 0, and when you get that later, you get jan1, 1970, since that's what it represents as a unix timestamp.)

    Just use time() to get the current timestamp (or date(), with no second parameter or input time), and display how you want. But always STORE the unix timestamp, and when you display it, be sure to do so as a date. It hurts nothing if you don't need the hour/min/sec. I did the same thing recently... it's fine.

    So.... I'd suggest, for ease of use, making a function, so you can call the formatting easily.

    PHP Code:
    <?php
    function t2d($t) {
    return 
    date('M j, Y',$t);
    }
    //format the date as you want... that gives ex: Jan 1, 1999

    ///do whatever else you want, including html... etc. etc.

    //later, call that function with t2d($time);....

    //example:
    echo t2d($time);
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •