Jump to content

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

Edited by Ch0cu3r
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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