-1

Hi i have some examples dates given below.How to find the next closest date in php or in mysql ?

I have some date like 12-04-2015 so now i need to get the closest date after the given date.So in my case my closest date is 15-04-2015.How can i find using PHP and mysql ?? Any one help me

PHP

$date = date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");

Mysql

SELECT Birthdate FROM hedging ORDER BY ABS(DATEDIFF(Birthdate , `2015-04-12`)) LIMIT 1 

How can i execute the above query in mysql ?

BirthDate
25-03-2015
10-04-2015
10-04-2015
11-04-2015
15-04-2015
30-04-2015
Question User
  • 99
  • 1
  • 2
  • 12

1 Answers1

1

You've not given us much information about what you've tried.

In PHP, store the dates in an array, you can then simply sort it and choose the next value.

In SQL so long as they are stored as dates, then WHERE date > $date ORDER BY date DESC LIMIT 1 will give you the next date.

Geoff Atkins
  • 1,693
  • 1
  • 17
  • 23