TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   since last update (http://www.talkphp.com/absolute-beginners/4864-since-last-update.html)

talonos 08-17-2009 02:50 PM

since last update
 
i'm trying to make a script and cant get any of them working

say i have a string:

PHP Code:

$lastupdate "2009-08-10 21:10:52"

from that i want to omit the 21:10:52 (time)

then calculate how many days have past and display it as

PHP Code:

echo " ' .$days. ' days since last update"

any help with this would be greatly appreciated

Talonos

JaoudeStudios 08-17-2009 02:54 PM

$date = substr($lastupdate, 0, 10); // will remove the time
$date_ = explode('-', $date);
$day = $date[2];

This is not ideal. What version of php are you running. The latest version (php 5.3) has some very cool and easy to use date manipulation functionality. Or you could use Zend_date to achieve the same. Else I would convert it to a unix time stamp and do the calculation from there.

talonos 08-17-2009 03:57 PM

my PHP Version is 5.2.10 and i cant update it :(

also your script works perfect m8 with a few adaptations :)

JaoudeStudios 08-17-2009 05:04 PM

Cool, glad it worked :)

ETbyrne 08-17-2009 06:15 PM

If you are using PHP 5.2 or better then you can use most of the DateTime functions:

PHP Code:

$date = new DateTime('2009-08-10 21:10:52');
echo 
$date->format('Y-m-d'); // Output 2009-08-10 

Check out these links

> http://us.php.net/manual/en/class.datetime.php
> http://us.php.net/manual/en/datetime.format.php
> http://us.php.net/manual/en/datetime.modify.php

JaoudeStudios 08-17-2009 06:28 PM

Really? I thought that was only in php5.3 and above?

ETbyrne 08-17-2009 06:30 PM

Check the links I gave to the docs. Only some of the DateTime functions require PHP 5.3. I'm running PHP 5.2.9 right now on my local box and it works perfectly.


All times are GMT. The time now is 01:44 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0