Click here to get back home

Manipulating date with "00" in it coming from mySQL

 HomeNewsGroups | Search

comp.lang.php - PHP programming language discussions 

get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Manipulating date with "00" in it coming from mySQL JackM 05-13-2009
Posted by Gordon Burditt on May 14, 2009, 5:05 pm
Please log in for more thread options
show/hide quoted text

PHP's strtotime() will correct the date for out-of-range values.
Day 0 is one day before Day 1, so you get the last day of the
previous month. Day 37 is 6 days after a 31-day month, so you get
day 06 of the next month.

Also, PHP's date type uses UNIX time stamps, so keep dates that might
be before 1970 OUT of that format. That especially includes '0000-00-00'
if you're trying to detect that.

show/hide quoted text

If you absolutely MUST feed this to date() or strtotime, fix the
day number to 01 (or any valid day for that month) first.

show/hide quoted text

Then change $date[2] to 01, implode it, and feed THAT to strtotime.

show/hide quoted text

strtotime() is doing what it is supposed to do.
If you want to stay in the same month, attach a valid day first.

show/hide quoted text



Posted by JackM on May 15, 2009, 8:57 am
Please log in for more thread options
Gordon Burditt wrote:
show/hide quoted text

Thanks Gordon. That explained a whole lot. It appears that since I do
have some pre-1970 dates and I don't want to display unknown days as 01
that using the date options of either PHP or mySQL won't do what I want.

It appears that my best option will be to split the date into three
fields in the database, one using the mySQL YEAR type and the other two
using integers that I can manipulate with if statements. I put a test
together using this and it is working the way that I want it to.

I appreciate the assistance from all in helping me reach a solution to
the problem.

Posted by Jerry Stuckle on May 15, 2009, 9:11 am
Please log in for more thread options
JackM wrote:
show/hide quoted text

Not necessary. Just keep it as a DATE field in MySQL (which has
multiple advantages) and explode() like I showed you earlier in PHP.

Much less overhead and easier to handle.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Posted by Gordon Burditt on May 15, 2009, 4:49 pm
Please log in for more thread options
show/hide quoted text

You don't have to use that "01", just put it in there to get the month
name correctly.

Don't paint *MySQL* date functions with the same problems as PHP date
functions. MySQL date functions have no 1970 or 2038 limit. A year
can go from 0000 to 9999.

show/hide quoted text

I don't see why you can't use year(field), month(field), and day(field),
then manipulate the results as strings with if statements.



Posted by =?ISO-8859-1?Q?=22=C1lvaro_G=2 on May 14, 2009, 3:32 am
Please log in for more thread options
JackM escribió:
show/hide quoted text

Nope. I'm suggesting that one of the possibilities is fetching the data
you need in the first place, rather than using a different format and
then transform it. My code was a sampler of some MySQL functions that
could help. Is it a strange approach?


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--

Similar ThreadsPosted
Help with comparing date stamp in PHP to date AND time stamp coming from MYSQL db!!!!!! May 8, 2008, 1:21 am
displaying a pdf coming out of a mysql-db in a frame October 8, 2004, 12:31 pm
Date is not being pulled from MYSQL database, instead current date is displayed!!! March 22, 2006, 12:29 pm
Put today's date into a MySQL "date" formated field August 3, 2006, 3:47 pm
manipulating forms December 12, 2006, 9:07 pm
Manipulating binary data April 29, 2007, 12:36 pm
manipulating multiple browser windows September 9, 2004, 4:44 pm
reading and manipulating vcalendar files June 12, 2005, 8:00 am
Manipulating an object returned from function July 13, 2007, 12:11 pm
POST variables not coming through August 29, 2006, 11:33 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap
Privacy Policy