- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Combine three strings (day, month, year) and calculate next date PHP?
You need to iterate using three for loops and lookup in given day, month and year. If the day, month and year is available, then put them into a variable.
Example
The PHP code is as follows
<!DOCTYPE html> <html> <body> <?php $givenDate = '2018-04-28'; $fiveYears = '2018,2019,2020,2021,2022'; $fiveMonths = '03,05,07,08,09'; $fiveDays = '25,26,27,28,29'; $fYears = explode(',', $fiveYears); $fMonths = explode(',', $fiveMonths); $fDays = explode(',', $fiveDays); $nextDate = null; foreach($fYears as $yr) { foreach($fMonths as $mn) { foreach($fDays as $dy) { $t = $yr.'-'.$mn.'-'.$dy; if($t > $givenDate) { $nextDate = $t; break 3; } } } } if($nextDate) { echo 'The next date value is =' . $nextDate; } else { echo 'No date is found.'; } ?> </body> </html>
Output
This will produce the following output
The next date value is =2018-05-25
- Related Articles
- Format MySQL date and convert to year-month-day
- Finding day of week from date (day, month, year) in JavaScript
- How to combine year, month, and day column in an R data frame?
- Create date from day, month, year fields in MySQL?
- How to get a Date from year, month and day in Java?
- How to convert year, month, and day of the month into a complete date in R?
- Extract the Day / Month / Year from a Timestamp in PHP MySQL?
- How to calculate average age by year/month/date in Excel?
- How to get day of month, day of year and day of week in android using offset date time API class?
- Convert day of year to day of month in Java
- Java Program to get current date, year and month
- MySQL query to fetch date with year and month?
- Sorting array of strings having year and month in JavaScript
- Filter the records of current day, month and year in MySQL?
- How to get current day, month and year in Java 8?

Advertisements