• 0

php, splitting a string. help !


Question

Hi..

i have a date, stored like this: 20020331203657

(31/03/2002 @ 20:36:57) (day/month/year hour/mins/sec)

i was wondering how i could possibly split this into seperate variables..

is there a function specifically for dates stored like this that will do it for me? or is there a way to split the string into characters.. like

$date[1] = token($datetime, 1);

really my aim is to output this as a date again (ie 31st March 2002 @ 08:36PM)

anyone have any ideas?

thx :)

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

ah yes, mysql timestamps. I hate them as well..

it's all in your sql query actually:

$query = "SELECT date_format(Timestamp_Field_Name, '%M %

d, %Y') AS Readable_Date from Table_Name";

Here's the list of formatting options:

%M Month name (January..December)

%W Weekday name (Sunday..Saturday)

%D Day of the month with English suffix (1st, 2nd, 3rd, etc.)

%Y Year, numeric, 4 digits

%y Year, numeric, 2 digits

%X Year for the week where Sunday is the first day of the week, numeric, 4 digits, used with '%V'

%x Year for the week, where Monday is the first day of the week, numeric, 4 digits, used with '%v'

%a Abbreviated weekday name (Sun..Sat)

%d Day of the month, numeric (00..31)

%e Day of the month, numeric (0..31)

%m Month, numeric (01..12)

%c Month, numeric (1..12)

%b Abbreviated month name (Jan..Dec)

%j Day of year (001..366) %H Hour (00..23)

%k Hour (0..23) %h Hour (01..12) %I Hour (01..12)

%l Hour (1..12)

%i Minutes, numeric (00..59)

%r Time, 12-hour (hh:mm:ss [AP]M)

%T Time, 24-hour (hh:mm:ss)

%S Seconds (00..59) %s Seconds (00..59)

%p AM or PM

%w Day of the week (0=Sunday..6=Saturday)

%U Week (0..53), where Sunday is the first day of the week

%u Week (0..53), where Monday is the first day of the week

%V Week (1..53), where Sunday is the first day of the week. Used with '%X'

%v Week (1..53), where Monday is the first day of the week. Used with '%x'

%% A literal `%'.

Hope that helps...

Link to comment
Share on other sites

  • 0

yeah i was having FUN with that earlier, it was messing up the time when i put time in at the end, came up with some random time that was completly wrong..

heh you should see the great code i have now! $hour = $timestamp[0] . $timestamp[1] . [$timestamp[2] . $timestamp[3];

hey it works (returns 2002..)

so my date is formed that way.. i could make it work properly, but that involves changing the database structure and a million other php scripts.. which aint happening!

thx for your help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.