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
https://forums.phpfreaks.com/topic/229762-date-question/
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
https://forums.phpfreaks.com/topic/229762-date-question/#findComment-1183516
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.