Jump to content

Date Range and Array


yagrasdemonde

Recommended Posts

Hello,

I'm very disapointed because I don't know how do it this.
I'm explain.
I have a database with one input date_arrival and second date_departure.
Two dates are saved in SQL format : 2014-03-02.

After my SQL request to select all dates in database I'd like to add dates between date_arrival and date_departure and for each line.
For example I have
date_arrival date_departure
line 1 : 2014-02-01 2014-02-05
line 2 : 2014-02-10 2014-02-15

In fact at the end, I have to send the result like this (with JSON) :

["2014-02-01","2014-02-02","2014-02-03","2014-02-04","2014-02-05","2014-02-10","2014-02-11","2014-02-12","2014-02-13","2014-02-14","2014-02-15"

Can you give me some help to add intermediates values in an array ?
Thx

Link to comment
https://forums.phpfreaks.com/topic/292537-date-range-and-array/
Share on other sites

You can use the built in DateTime class to generate the dates between the start and end dates

 

Look at the DatePeriod examples here

http://php.net/manual/en/dateperiod.construct.php

 

To encode the dates into JSON add each date to an array and then use json_encode

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.