I have arrays of dates Y-m-din Y-m-d format that may be any combination of ten set dates that are zero, one day, or more days apart.
e.g. Here is a possible full set:
[
'2011-01-01',
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-05',
'2011-01-06',
'2011-01-07',
'2011-01-08',
'2011-01-09',
'2011-01-10'
]
The arrays that are created from that set can be any combination of dates— all of them, one of them, some consecutive, all consecutive, etc or gapped dates.
I currently have them printing pretty much as they're returned. e.g. here's another possible data set:
[
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-08',
]
(what'sWhat's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string.)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
[
'2011-01-02 to 2011年01月04日',
'2011-01-08',
]
which would eventually become:
[
'Sunday, Jan. 2 - Tuesday, Jan. 4',
'Saturday Jan. 8',
]
Is there a way to loop through and check the time difference, create a start time and end time for the range(s), and then gather up the stragglersconsolidate consecutive dates as ranged date strings?
I have arrays of dates Y-m-d format that may be any combination of ten set dates that are one day apart.
e.g. Here is a possible full set:
[
'2011-01-01',
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-05',
'2011-01-06',
'2011-01-07',
'2011-01-08',
'2011-01-09',
'2011-01-10'
]
The arrays that are created from that set can be any combination of dates— all of them, one of them, some consecutive, all consecutive, etc.
I currently have them printing pretty much as they're returned. e.g. here's another possible data set:
[
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-08',
]
(what's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
[
'2011-01-02 to 2011年01月04日',
'2011-01-08',
]
which would eventually become:
[
'Sunday, Jan. 2 - Tuesday, Jan. 4',
'Saturday Jan. 8',
]
Is there a way to loop through and check the time difference, create a start time and end time for the range(s), and then gather up the stragglers?
I have arrays of dates in Y-m-d format that may be any combination of ten set dates that are zero, one, or more days apart.
e.g. Here is a possible full set:
[
'2011-01-01',
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-05',
'2011-01-06',
'2011-01-07',
'2011-01-08',
'2011-01-09',
'2011-01-10'
]
The arrays that are created from that set can be any combination of consecutive or gapped dates.
I currently have them printing pretty much as they're returned. e.g. here's another possible data set:
[
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-08',
]
(What's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string.)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
[
'2011-01-02 to 2011年01月04日',
'2011-01-08',
]
which would eventually become:
[
'Sunday, Jan. 2 - Tuesday, Jan. 4',
'Saturday Jan. 8',
]
Is there a way to loop through and consolidate consecutive dates as ranged date strings?
- 49.3k
- 13
- 98
- 165
Check for Create date ranges from consecutive dates within a set and return as rangein an array
I have arrays of dates Y-m-d format that may be any combination of ten set dates that are one day apart.
e.g. Here is thea possible full set:
2011年01月01日, 2011年01月02日, 2011年01月03日, 2011年01月04日, 2011年01月05日, 2011年01月06日, 2011年01月07日, 2011年01月08日, 2011年01月09日, 2011年01月10日
[
'2011-01-01',
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-05',
'2011-01-06',
'2011-01-07',
'2011-01-08',
'2011-01-09',
'2011-01-10'
]
The arrays that are created from that set can be any combination of dates— all of them, one of them, some consecutive, all consecutive, etc.
I currently have them printing pretty much as they're returned. e.g. here's aanother possible resultdata set:
2011年01月02日
2011年01月03日
2011年01月04日
2011年01月08日
[
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-08',
]
(what's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
2011年01月02日 to 2011年01月04日
2011年01月08日
[
'2011-01-02 to 2011年01月04日',
'2011-01-08',
]
which would eventually become:
Sunday, Jan. 2 - Tuesday, Jan. 4
Saturday Jan. 8
[
'Sunday, Jan. 2 - Tuesday, Jan. 4',
'Saturday Jan. 8',
]
Is there a way to loop through and check the time difference, create a start time and end time for the range(s), and then gather up the stragglers?
Check for consecutive dates within a set and return as range
I have arrays of dates Y-m-d format that may be any combination of ten set dates that are one day apart.
e.g. Here is the full set:
2011年01月01日, 2011年01月02日, 2011年01月03日, 2011年01月04日, 2011年01月05日, 2011年01月06日, 2011年01月07日, 2011年01月08日, 2011年01月09日, 2011年01月10日
The arrays that are created from that set can be any combination of dates— all of them, one of them, some consecutive, all consecutive, etc.
I currently have them printing pretty much as they're returned. e.g. here's a possible result:
2011年01月02日
2011年01月03日
2011年01月04日
2011年01月08日
(what's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
2011年01月02日 to 2011年01月04日
2011年01月08日
which would eventually become:
Sunday, Jan. 2 - Tuesday, Jan. 4
Saturday Jan. 8
Is there a way to loop through and check the time difference, create a start time and end time for the range(s), and then gather up the stragglers?
Create date ranges from consecutive dates in an array
I have arrays of dates Y-m-d format that may be any combination of ten set dates that are one day apart.
e.g. Here is a possible full set:
[
'2011-01-01',
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-05',
'2011-01-06',
'2011-01-07',
'2011-01-08',
'2011-01-09',
'2011-01-10'
]
The arrays that are created from that set can be any combination of dates— all of them, one of them, some consecutive, all consecutive, etc.
I currently have them printing pretty much as they're returned. e.g. here's another possible data set:
[
'2011-01-02',
'2011-01-03',
'2011-01-04',
'2011-01-08',
]
(what's actually printed is more like "Friday, Jan. 2...", but we'll stick with the simple date string)
I'd like to condense it so that if there are three or more consecutive days, those become a range, e.g the above example would become:
[
'2011-01-02 to 2011年01月04日',
'2011-01-08',
]
which would eventually become:
[
'Sunday, Jan. 2 - Tuesday, Jan. 4',
'Saturday Jan. 8',
]
Is there a way to loop through and check the time difference, create a start time and end time for the range(s), and then gather up the stragglers?