PHP Date Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TomG1989
Forum Newbie
Posts: 2
Joined: Mon Aug 02, 2010 6:49 am

PHP Date Help

Post by TomG1989 »

Hi Guys,

I'm not the best coder in the world, i'll attempt new/different things every now and again...

I've created a signup script to a website, where i have added an Update set **sign up's name** into a field called 'datesignup' on my MYSQL Db.

set users datesignup=$now
$now being: $now = date("m-d-y h:i:s A T");

When the user signs up it adds the date of the sign up into a field on a MYSQL DB as desired but..

I'm trying to use this date an replicate it on another page on my website where it shows when the user signed up.

I want it too state "Member for: ** years, ** Months, ** days, **Minutes .... but i cant seem to work out how to do this..

Currently im using print"Member For: $get[datesignup]<br>"; which is stating the date as 08-02-10 07:24:46 AM EDT which is what's being added in the signup script.

Anyone know how i can get this working - Apologise if wrong forum but it's my first post!
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: PHP Date Help

Post by internet-solution »

TomG1989
Forum Newbie
Posts: 2
Joined: Mon Aug 02, 2010 6:49 am

Re: PHP Date Help

Post by TomG1989 »

How shall i write it out? Can't get it to work..

the field is $datesignup
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: PHP Date Help

Post by buckit »

just google: php time between dates

you'll find lots of functions that can give you the output you are looking for.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: PHP Date Help

Post by internet-solution »

TomG1989 wrote:How shall i write it out? Can't get it to work..

the field is $datesignup
Did you visit the link I posted above? It contains the following sample code:

Code: Select all

<?php

$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);

// %a will output the total number of days.
echo $interval->format('%a total days')."\n";

// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');

?>
The above example will output:

Code: Select all

31 total days
1 month, 0 days
Post Reply