Date subtraction - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Date subtraction (/showthread.php?tid=20285) |
Date subtraction - El Forum - 07-04-2009 [eluser]ilSignorCarlo[/eluser] Hi, I need to perform some "simple" operations on dates, for example: getting the distance in days between two dates, or between now and a date in the past. Code: $previous_date = '2009-07-03'; This prints 02, but I'm not sure what it is. I mean, if it represents days, it should be 01. Where am I wrong? Thanks. Date subtraction - El Forum - 07-04-2009 [eluser]jedd[/eluser] Why not use timespan() ? Date subtraction - El Forum - 07-04-2009 [eluser]garymardell[/eluser] Code: $previous_date = '2009-07-03'; Not saying this is the best way to do it, just made your code example work. Date subtraction - El Forum - 07-04-2009 [eluser]jedd[/eluser] In my views I make a call to a function in my helper: Code: echo pdb_rough_time_ago (mysql_to_unix($msgdate)) . " ago"; $msgdate is in mysql format, of course. One day I'll write my helper function to be a bit more adept at recognising and coping with different date formats. My helper contains: Code: /** While this diverges slightly from the original question - it's a 'rough time' example after all - it gives an idea of the benefits of using [url="http://ellislab.com/codeigniter/user-guide/helpers/date_helper.html"]CI's date helper[/url] (which is kind of the point isn't it)? Date subtraction - El Forum - 07-04-2009 [eluser]ilSignorCarlo[/eluser] [quote author="jedd" date="1246738247"]Why not use timespan() ?[/quote] You're right, I just didn't see it Thanks for the other solutions too. |