Forum Moderators: coopster

Message Too Old, No Replies

Formating a string with date information

Not typical I suppose?

         

JAB Creations

2:56 pm on May 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This thread is based off and a resuilt of my messing with Plastic Shore's AJAX chat which I've known and even used previously on a previous client's site for about a year.

In the MySQL database is a column called time. Values look like this...

20060509133444
20060509133450
20060509133455

Format broken down...
2006-05-09-13-34-55
year,month,day,hour,min,sec

I was able to replicate pulling the information from this column per post/row and inserting it as a time stamp.

However the issue is formating!

I initially have the unformated variable as $time1. I'd like to run a miniscript (what we're doing here) to reformat the script just a little and then assign that to $time2 variable (which I can then insert for echo-ing as part of the post).

So I want
$time1 = '20060509133455';
to be spat out as...
$time2 = 'May 09, 2006 13:34:55';

I'm fine with breaking it down in to extra steps (and bumping up the number on the time variable if need be).

- John

*PS/Note - If you can not get his chat script to work on your server check your phpinfo to check if your register_globals are set to off. If they are you'll want to read and implement some very basic changes to one of the script files. While the directions say to mod two files, I had to re-upload an original (manually patching one file works, but I forgot which needed the patch and which didn't).

whoisgregg

4:16 pm on May 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the column type in MySQL is date or timestamp, then you can use a mysql function
SELECT UNIX_TIMESTAMP(`datecolumn`) AS datecolumnTS FROM...
then feed the result through PHP's date() [php.net] function.

Otherwise, you can parse out the string into PHP's mktime() [php.net] function to get the timestamp. And, again feed it through the date() function for formatting.

siMKin

3:33 pm on May 10, 2006 (gmt 0)

10+ Year Member



you can also format it in mysql:
[dev.mysql.com...]
see for example DATE_FORMAT()