How to get the first day of the current year?
In PHP, you can use the mktime
function to get the Unix timestamp of the first day of the current year, then use the date
function to format it as a date string.
Here's an example:
<?php
$firstDayOfYear = mktime(0, 0, 0, 1, 1, date("Y"));
$firstDayOfYear = date("Y-m-d", $firstDayOfYear);
echo $firstDayOfYear;
The mktime
function creates a timestamp based on the parameters provided: hour (0), minute (0), second (0), month (1, January), day (1), and year (the current year, obtained using the date
function with the format "Y").
The date
function then formats the timestamp as a date string in the format "Y-m-d".