다음 월요일, 화요일 등의 날짜 가져 오기
월요일, 화요일, 수요일 등의 날짜 스탬프를 찾고 싶습니다. 아직 그 날이 이번 주에 오지 않았다면, 날짜를 이번 주, 그렇지 않은 경우 다음 주로 지정하고 싶습니다. 감사!
보다 strtotime()
strtotime('next tuesday');
주 번호를 살펴보면 그날지나 갔는지 알 수 있습니다.
$nextTuesday = strtotime('next tuesday');
$weekNo = date('W');
$weekNoNextTuesday = date('W', $nextTuesday);
if ($weekNoNextTuesday != $weekNo) {
//past tuesday
}
약간 늦은 답변이라는 것을 알고 있지만 향후 참조를 위해 답변을 추가하고 싶습니다.
// Create a new DateTime object
$date = new DateTime();
// Modify the date it contains
$date->modify('next monday');
// Output
echo $date->format('Y-m-d');
좋은 점은 오늘 이외의 날짜로도이 작업을 수행 할 수 있다는 것입니다.
// Create a new DateTime object
$date = new DateTime('2006-05-20');
// Modify the date it contains
$date->modify('next monday');
// Output
echo $date->format('Y-m-d');
범위를 만들려면 :
$monday = new DateTime('monday');
// clone start date
$endDate = clone $monday;
// Add 7 days to start date
$endDate->modify('+7 days');
// Increase with an interval of one day
$dateInterval = new DateInterval('P1D');
$dateRange = new DatePeriod($monday, $dateInterval, $endDate);
foreach ($dateRange as $day) {
echo $day->format('Y-m-d')."<br />";
}
참고 문헌
PHP 매뉴얼 -DateTime
PHP 매뉴얼 -DateInterval
PHP 매뉴얼 -DatePeriod
PHP Manual- 복제
질문에 "php"태그가 지정되어 있으므로 Tom이 말했듯이이를 수행하는 방법은 다음과 같습니다.
date('Y-m-d', strtotime('next tuesday'));
Sorry, I didn't notice the PHP tag - however someone else might be interested in a VB solution:
Module Module1
Sub Main()
Dim d As Date = Now
Dim nextFriday As Date = DateAdd(DateInterval.Weekday, DayOfWeek.Friday - d.DayOfWeek(), Now)
Console.WriteLine("next friday is " & nextFriday)
Console.ReadLine()
End Sub
End Module
You can use Carbon library.
Example: Next week friday
Carbon::parse("friday next week");
If I understand you correctly, you want the dates of the next 7 days?
You could do the following:
for ($i = 0; $i < 7; $i++)
echo date('d/m/y', time() + 86400 * $i);
Check the documentation for the date function for the format you want it in.
if you want to find Monday then 'dayOfWeek' is 1 if it is Tuesday it will be 2 and so on.
var date=new Date();
getNextDayOfWeek(date, 2);
// this is for finding next tuesday
function getNextDayOfWeek(date, dayOfWeek) {
// Code to check that date and dayOfWeek are valid left as an exercise ;)
var resultDate = new Date(date.getTime());
resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
return resultDate;
}
Hope this will be helpfull to you, thank you
PHP 7.1:
$next_date = new DateTime('next Thursday');
$stamp = $next_date->getTimestamp();
PHP manual getTimestamp()
The PHP documentation for time() shows an example of how you can get a date one week out. You can modify this to instead go into a loop that iterates a maximum of 7 times, get the timestamp each time, get the corresponding date, and from that get the day of the week.
참고URL : https://stackoverflow.com/questions/1188728/get-the-date-of-next-monday-tuesday-etc
'program story' 카테고리의 다른 글
| Google지도 API V3 메서드 fitBounds () (0) | 2020.11.16 |
|---|---|
| C #의 Zip 폴더 (0) | 2020.11.16 |
| 특정 유형의 파일에 대한 폴더 및 모든 하위 폴더 검색 (0) | 2020.11.16 |
| 권한 파일이 프로비저닝 프로필에 지정된 것과 일치하지 않습니다. (0xE8008016) (0) | 2020.11.16 |
| 포인터가 가리키는 int의 증가 값 (0) | 2020.11.15 |