Results 1 to 12 of 12

Thread: Get the Date & Time From A MySQL Time Stamp? -Solved[:)]-

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    Get the Date & Time From A MySQL Time Stamp? -Solved[:)]-

    OK, now if i create a record in my table, (mysql) i have a timestamp field, so it fills in like:

    20021201214855

    Translated To:
    Date: 01 December 2002
    Time: 21:48:55

    Now, i know its in the form:

    YearMonthDayHourMinuteSecond

    But, is there a way (Already made) That will make it into an easy to read manner?

    And if i can split it into the actual Date & Time seperate, Cool
    Last edited by wpearsall; Dec 2nd, 2002 at 05:57 PM.
    Wayne

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Use the Date() function:

    Code:
    Date('d m Y', $time_stamp_here)
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Doesn't seam to do the trick?

    20021201214855 -> 19 01 2038

    using:

    PHP Code:
    Date('d m Y',$lutimestamp
    & Using:


    PHP Code:
    Date('d m Y',"20021201214855"

    Tnx,
    Wayne

  4. #4

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Don't Spose theres a Left$() + Right$() Function in php?
    Wayne

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It should work fine...

    No, there is no Left() or Right(). Use the substr() function.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Are you misunderstanding the format of a unix timestamp? I don't know much about them, so I'm not sure, but when I run this code:

    Code:
    echo mktime(11, 41, 11, 12, 1, 2002);
    I get '1038760871' for the timestamp.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Oh, it isn't on a *nix system,
    It's on a Win2k Pro SP3 Server.
    I Will Test The date() Thing On My Hosted Server L8r.

    Are you misunderstanding the format of a unix timestamp?
    Im not certain, This is the TimeStamp field for a MySQL Database Feild,
    I am importing a CSV File regularly, & want to b able to get the time the file was imported, without altering the file to add the time to 200 + records manually.

    PHP Code:
    echo mktime(1141111212002); 
    Say What? (Little Lost @ This?)

    Use the substr() function
    OK, will look @ The manual 4 this when i get bk from college, split the date & Time from the stamp manually if all else fails.
    Wayne

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You don't have to be on a unix system to use a unix timestamp.

    And as far as I know, they are the only kind of timestamps used by PHP and MySQL. Anyone who knows better, feel free to ring in now.

    The mktime() function returns a unix timestamp based on the date you give it:

    Code:
    echo mktime(HOUR, MINUTE, SECOND, MONTH, DAY, YEAR);
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    And you are right about the format of the timestamp, according to http://www.mysql.com/doc/en/DATETIME.html

    I'm not sure why that function doesn't create it in that format. I suppose UNIX Timestamps are different than MySQL Timestamps afterall?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    OK, got the substr function down too now (Bonus or what )

    So i got the date & Time Like:

    PHP Code:
    <?php
    // Date - Day / Month / Year
    echo substr($lutimestamp6,2)."/".substr($lutimestamp4,2)."/".substr($lutimestamp0,4);
    ?>

    <?php
    // Time - Hour:Minute
    echo substr($lutimestamp8,2).":".substr($lutimestamp10,2);
    ?>
    and seams to work kool,
    Wayne

  11. #11

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Originally posted by The Hobo
    You don't have to be on a unix system to use a unix timestamp.

    And as far as I know, they are the only kind of timestamps used by PHP and MySQL. Anyone who knows better, feel free to ring in now.

    The mktime() function returns a unix timestamp based on the date you give it:

    Code:
    echo mktime(HOUR, MINUTE, SECOND, MONTH, DAY, YEAR);
    Little extra note with this,

    So, if i decided to [not sure yet but probally will] make a forum, to go wiv the portal / site im buildin now,

    When i add the date the post's are made the the database,

    I add it like:

    PHP Code:
    mktime(date("h"), date("i")... 
    and then i can get it back to normal, With the users setting of the date / time by the:

    PHP Code:
    date($user_format$post_time); 
    Correct?

    : BTW, when u fink that vbsboard will have a public release,
    : Cuz their comin on well,
    Wayne

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by wpearsall
    When i add the date the post's are made the the database,

    I add it like:

    PHP Code:
    mktime(date("h"), date("i")... 
    Actually (don't know why I didn't use this before), do this:

    Code:
    strtotime("now");
    Should give you the correct timestamp.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width