Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Converting a timestamp to a readable date in php?

  • 27-05-2006 11:50pm
    #1
    Closed Accounts Posts: 850 ✭✭✭


    Hey,

    If I have a date stored in my database like this -

    20060528000145

    (YYYYMMDDHHMMSS)

    - what's the easist way to convert it to this -

    May 28, 2006 @ 00:01 PM

    - in PHP? (notice I don't care about the seconds.)

    Does anyone know?

    Thank you.


Comments

  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    [PHP]<?=format(gmdate("d-M-Y"),"dddd, dd mmmm")?>[/PHP]

    Should do the trick, I dunno about the @ 00:01 PM bit though sorry! Thats GMT by the way.


  • Closed Accounts Posts: 850 ✭✭✭DOLEMAN


    Hey,

    Thanks for the reply.

    Am I right in thinking that will return the current date/time?

    How do I pass in my variable with the unix timestamp?

    Thanks!


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    Sorry, scratch that!! I have a whole function called 'format' behind that, it wont work for you! But that print method will give you the correct format, you've just got to write a little format function for yourself. As for passing the UNIX timestamp, just reformat it to unix as a variable for passing to the database.


  • Registered Users, Registered Users 2 Posts: 689 ✭✭✭JoeB-


    Use
    timeS = mktime($str[9].$str[10], $str[11].$str[12] ... etc)

    to get a timestamp equivelent to your database string... you have to supply the values for the hour, min etc by choosing letters from your database string... ($str equals your database string and $str[12] = the 12th letter)

    int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )


    then call
    Date("M d, Y @ h:i A", timeS)

    to convert the timestamp to the required format.


  • Closed Accounts Posts: 850 ✭✭✭DOLEMAN


    Actually... got it working...

    my query... DATE_FORMAT(date, '%W, %M %d, %Y') AS date ...

    Works grand!

    Thanks for the help :)


  • Advertisement
Advertisement