TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-17-2009, 02:50 PM   #1 (permalink)
The Wanderer
 
Join Date: Jul 2009
Posts: 10
Thanks: 1
talonos is on a distinguished road
Help 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
talonos is offline  
Reply With Quote
Old 08-17-2009, 02:54 PM   #2 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

$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.
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-17-2009, 03:57 PM   #3 (permalink)
The Wanderer
 
Join Date: Jul 2009
Posts: 10
Thanks: 1
talonos is on a distinguished road
Default

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

also your script works perfect m8 with a few adaptations :)
talonos is offline  
Reply With Quote
Old 08-17-2009, 05:04 PM   #4 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Cool, glad it worked :)
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
The Following User Says Thank You to JaoudeStudios For This Useful Post:
talonos (08-17-2009)
Old 08-17-2009, 06:15 PM   #5 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 08-17-2009, 06:28 PM   #6 (permalink)
The Acquainted
 
JaoudeStudios's Avatar
 
Join Date: Jul 2009
Location: Surrey
Posts: 105
Thanks: 1
JaoudeStudios is on a distinguished road
Default

Really? I thought that was only in php5.3 and above?
__________________
JaoudeStudios.com | JaoudeStudios.com Forum | JaoudeStudios.com Blog
OpenSource is the road ahead...!
JaoudeStudios is offline  
Reply With Quote
Old 08-17-2009, 06:30 PM   #7 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

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.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
UPDATE MySQL data via web forms? Randy Absolute Beginners 26 05-07-2009 02:31 AM
mysql update with multi fields sarmenhb Absolute Beginners 1 02-06-2009 10:03 PM
Can you use IGNORE in the update of a mysql row ? codefreek General 5 11-17-2008 12:45 AM
You are subscribed to this thread mysql update with multi fields sarmenhb Advanced PHP Programming 0 11-15-2008 05:00 AM
mysql update with multi fields sarmenhb General 0 11-15-2008 04:19 AM


All times are GMT. The time now is 01:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design