Web Hosting Forums

Results 1 to 4 of 4

This is a discussion on MySQL Date Question in the Hosting Talk & Chit-chat forum
I have a date stored in a MySQL database in the form like 2002-02-15 or something. With the use of PHP (I'm still kinda new ...

  1. #1
    Loyal Client
    Join Date
    Jan 2002
    Posts
    30

    MySQL Date Question

    I have a date stored in a MySQL database in the form like 2002-02-15 or something. With the use of PHP (I'm still kinda new to it), I would like to transform it into and image form. I already have images like february.gif and all of the numbers like 0.gif and 5.gif and also a comma. What is the best way to do this? I like to use the image because of the specific font I have and the way it looks, thanks.

    -bonk

  2. #2
    Loyal Client
    Join Date
    Feb 2002
    Posts
    6
    Not sure what exactly you want to do with the image names, but this might help give you a start:

    Parse the date into year,month, day variables:
    list ($Y,$M,$D)=split("-",$thedate);

    Then use those variables to format them with the date function:
    // Full name of month ("January")
    $monthname=date("F", mktime(0,0,0,$M,$D,$Y));


    then i guess you'd have stuff like
    <img src="/images/<?=$monthname?>.gif">
    <img src="/images/<?=$D?>.gif">

    hope this helps

  3. #3
    Loyal Client
    Join Date
    Jan 2002
    Posts
    30
    From what I see, it sounds like it will work, but I don't understand all of that PHP code. I'm still new to this stuff. list and mktime are the areas I'm most confused with.

    -bonk

  4. #4
    Loyal Client
    Join Date
    Feb 2002
    Posts
    6
    There are good examples at http://www.php.net/manual/en/function.date.php

    split returns an array by default, so what you're doing with list is instead dumping the array of results into 3 distinct variables.

    mktime just formats some numbers into a unix timestamp that the php date function can understand. It should be noted that to get today's date, you don't need mktime or a time stamp, just something like
    $today = date("F j, Y, g:i a");

    php is so much fun =)

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
  •