need help with Time function

General discussions related to php

Moderators: macek, egami, gesf

slayn27
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Jul 08, 2012 8:07 pm

need help with Time function

Postby slayn27 » Tue Jul 31, 2012 7:21 pm

I am making a forum and my problem is I need codes to determine how many years,months,days old the post is.

Thanks in advance :)

User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 283
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: need help with Time function

Postby freshnet » Wed Aug 01, 2012 5:21 am

As always, let us know what code you have and what point you are stuck at. You will need to record the forum post date/time in a database.

slayn27
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Jul 08, 2012 8:07 pm

Re: need help with Time function

Postby slayn27 » Fri Aug 03, 2012 5:38 pm

sorry for the late reply sir..I already have a database.. I need a sample code for subtracting time and instead of "mm/dd/yy" format i want to display it in total days or totalmonths or totalyears

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: need help with Time function

Postby johnj » Fri Aug 03, 2012 7:25 pm

pseudo code:

Code: Select all

1.get the posted date
2. get todays' date
3.get the difference between 1 and 2
4.convert the difference to seconds
5.Now, the convert the difference to months or days or years


This article may help you to some extent:
http://phillipnb.wordpress.com/2012/04/ ... ds-in-php/


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron