note 129938 added to datetimeimmutable.setisodate
| From: | theking2@king.ma | Date: | Thu, 02 Jan 2025 13:05:25 +0000 |
| Subject: | note 129938 added to datetimeimmutable.setisodate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221749@lists.php.net to get a copy of this message | ||
For a ETL loading dated csv files I needed a way to archive the files on a per week basis, starting
with monday's. For human readabily besides year and weeknr I wanted to include the start date
of the week in Swiss fmt) as well.
This is the function I ended up using:
<?php
function getArchiveName(string $date) {
$date = new \DateTimeImmutable($date);
$year = $date->format('o');
$week = $date->format('W');
$week_start = (new \DateTimeImmutable())->setISODate( $year, $week, 1 );
return $date->format('o_\k\wW') . $week_start->format('_(d.m.Y)');
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 62.112.9.237)
----
Manual Page -- https://php.net/manual/en/datetimeimmutable.setisodate.php
Edit -- https://main.php.net/note/edit/129938
Del: integrated -- https://main.php.net/note/delete/129938/integrated
Del: useless -- https://main.php.net/note/delete/129938/useless
Del: bad code -- https://main.php.net/note/delete/129938/bad+code
Del: spam -- https://main.php.net/note/delete/129938/spam
Del: non-english -- https://main.php.net/note/delete/129938/non-english
Del: in docs -- https://main.php.net/note/delete/129938/in+docs
Del: other reasons-- https://main.php.net/note/delete/129938
Reject -- https://main.php.net/note/reject/129938
Search -- https://main.php.net/manage/user-notes.php