Help - Search - Member List - Calendar
Full Version: Date Formating script
WorkTheWeb Forums > Web Hosting Help > PHP Help
Support our Sponsors!
noe0729
I have written a little script that will take a 12 digit date and time (ex. ) from your database or hard code and format it into something more readable (Mar 5, 2005 6:30pm). If you want to download it I have it on my site at the following address:

http://www.dustinnoe.com/index.php?page=Dev%20Zone

Feel free to leave a comment with any suggestion to make the function better.
phpfreak
QUOTE(noe0729 @ Mar 5 2005, 02:36 PM)
I have written a little script that will take a 12 digit date and time (ex. ) from your database or hard code and format it into something more readable (Mar 5, 2005 6:30pm).  If you want to download it I have it on my site at the following address:

http://www.dustinnoe.com/index.php?page=Dev%20Zone

Feel free to leave a comment with any suggestion to make the function better.
*



Interesting script. Why not just store dates in the database using the standard UNIX timestamp with PHP's time() function, and then use PHP's date functions to convert it to date however you want? It's much easier and requires much less effort.

Take a look at: http://php.net/date and http://php.net/time

Also: http://dev.mysql.com/doc/mysql/en/date-and-time-types.html

In all of the applications we write and use, we always store the time in a timestamp and if you want, you can also store a friendlier format for browsing the database using the MySQL DATE or DATETIME column types and simply pass in 'now()' as the input field for the query.

Just trying to take a more logical approach...
noe0729
QUOTE(phpfreak @ Mar 5 2005, 03:37 PM)
Interesting script. Why not just store dates in the database using the standard UNIX timestamp with PHP's time() function, and then use PHP's date functions to convert it to date however you want? It's much easier and requires much less effort.

Take a look at: http://php.net/date and http://php.net/time

Also: http://dev.mysql.com/doc/mysql/en/date-and-time-types.html

In all of the applications we write and use, we always store the time in a timestamp and if you want, you can also store a friendlier format for browsing the database using the MySQL DATE or DATETIME column types and simply pass in 'now()' as the input field for the query.

Just trying to take a more logical approach...
*



I know how to use date() to get the current time but I have never put my own time stamp into it. Would I do it like this?
CODE

date("F j, Y, g:i a", $my_time_stamp)

phpfreak
QUOTE(noe0729 @ Mar 6 2005, 06:03 AM)
I know how to use date() to get the current time but I have never put my own time stamp into it.  Would I do it like this?
CODE

date("F j, Y, g:i a", $my_time_stamp)

*




Yep, that's right. You get $my_time_stamp from the database or from the time() function and then pass it into there.
noe0729
QUOTE(phpfreak @ Mar 6 2005, 10:53 AM)
Yep, that's right. You get $my_time_stamp from the database or from the time() function and then pass it into there.
*


Cool. I was bored when I wrote that script anyway.
dtaberner
QUOTE(phpfreak @ Mar 5 2005, 08:37 PM)
Interesting script. Why not just store dates in the database using the standard UNIX timestamp with PHP's time() function, and then use PHP's date functions to convert it to date however you want? It's much easier and requires much less effort.
*



I just happend to be wondering how I was going to do this exact thing.. I currently have in tab one of firefox, php.net/time and the second tab is my site and the third is here.

Amazing timing.

While the unix time stamp is not nice to look at, its easy to change to other things, even in another launuage like c++ .

Cheers,

Caveman

PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.