Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Converting a timestamp to a readable date in php?

  • 28-05-2006 12:50AM
    #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