SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I"m going crazy!!!! Date function with timestamp problem

    Problem:
    I have the following unix timestamp as a var: 2003-10-02 08:00:00
    The var is $start_datetime.

    I need to use the date function like so:
    date('m/h/Y', $start_datetime) to make the date formatted better.

    My problem is that date('m/h/Y', $start_datetime) = 12/06/1969

    So I thought, ahh - for some reason it's not a correctly formatted timestamp, so I tried:

    date('m/h/Y', strtotime($start_datetime)) = 10/08/2003 - what happened here? - looks like strtotime gave me the 8th?

    What is the deal! I've worked for over an hour on this! I want 10/02/2003! See something I'm missing? For codeflow reasons, I'd rather not use mysql to format this string for me.

    Any assistance is appreciated!

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you locked into the timestamp column? Unfortunately, it is not a Unix Timestamp and the date() function takes a unixtimestamp. You can

    a) Change the timestamp column to something in line with int(11) and insert a UNIX_TIMESTAMP() into MySQL on insert, or

    b) look at mktime() and try to parse out the segments of the timestamp and generate a unixtimestamp in that manner and use that withe the date() function.

    Semantically, the second one is more correct. Practically, the first one is simpler and easier.

    Aaron
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    date('m/h/Y', strtotime($start_datetime))

    m = month

    h = hour !!!!!!!!!!!

    Y = year

    I think you need 'd' there ...

  4. #4
    SitePoint Member
    Join Date
    Oct 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, of course I need d in there! I was just checking to see if you knew!


    just kidding and thanks, Doh!!!!!!!!!!!!!!!!!


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
  •