Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 920
  • Last Modified:

PHP strtotime limit workaround??

Hi I am using this code to determine a date range. If a user selects the age 25-30 I want to compare that to a date in my mysql database.
My code is
 $today=date("Y-m-d");
//$age-group is  packed 25|30
 $age_gr=explode("|",$age_group);
 $start_date=date("Y-m-d", strtotime("$today - $age_gr[0] years"));
 $end_date=date("Y-m-d", strtotime("$today - $age_gr[1] years"));

This works perfectly, as long as the user is under 40.
Is there a work around to allow me to use any age up to 115?

 
$today=date("Y-m-d");
 
 $age_gr=explode("|",$age_group);
 $start_date=date("Y-m-d", strtotime("$today - $age_gr[0] years"));
 $end_date=date("Y-m-d", strtotime("$today - $age_gr[1] years"));

Open in new window

0
birwin
Asked:
birwin
  • 4
1 Solution
 
Ray PaseurCommented:
I'm sure we can work this out.  What are the age groups you want?
0
 
Ray PaseurCommented:
Also, what level of PHP and what platform are you using?
0
 
Ray PaseurCommented:
This seems to get us back to about 1902.  Not trying to be a prick, but anybody born in 1902 is not likely to be using the WWW.

Does that help? ~Ray
<?php // RAY_age_groups.php
 
$age_groups = array(25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 106, 107, 108, 109, 110, 111, 115);
 
foreach ($age_groups as $years_ago)
{
   $birthday = date('Y-m-d', strtotime('today ' . "- $years_ago years"));
   echo "<br/>$years_ago YEARS AGO - BIRTHDAY IS $birthday \n";
}

Open in new window

0
 
birwinAuthor Commented:
Ray, I was wrong. My code did work. I had picked 35 to 40, saw the dreaded 1969 UNIX date, and assumed it didn't work, but 1969 was the right date for the range I chose.

You have helped me before, so I am glad to award the points.

Brian
0
 
Ray PaseurCommented:
Amazing!  I would have looked at 1969 and thought the same thing.  ;-)  Thanks for the points and for the good question.  Best, ~Ray
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now