Jump to content

Date question


Porl123

Recommended Posts

I have a php script that allows the user to enter a day, month and year, for example 10/10/2001. What I'm trying to do is find out how many years that date is from now, taking into account the days and months along with the years. So say I have the variables:

 

<?php

$day = 10;

$month = 10;

$year = 2001;

?>

 

I've been thinking about this for a while now and I can't really think of how I would do it. If anyone can give me a hand I'd really appreciate it. (: Thanks!

Link to comment
Share on other sites

first you find the difference between the two years and then you should have two if statements checking the following

 

1. is the given month higher than the current month

2. is the given month equal to the current month, if so, is the given day higher than the current day?

 

if any of those are true you should substract 1 from the year difference

 

NOTE: If you don't check if the year is zero then you will end up with -1

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.