use now() helper function
Create date from string 'm.Y'
I have a problem with creating date from string with Carbon. For example I have a string 02.2022 which represent month (February) and year but when I use
Carbon::createFromFormat('m.Y', $date)
I store 2022-03-03 :(
How can I prevent this behaviour or at least to store 2022-02-01?
Try this:
Carbon::createFromFormat('!m.Y', '02.2022')
Which returns 2022-02-01
More information on the ! character here.
Resets all fields (year, month, day, hour, minute, second, fraction and timezone information) to zero-like values ( 0 for hour, minute, second and fraction, 1 for month and day, 1970 for year and UTC for timezone information)
Without !, all fields will be set to the current date and time.
Please or to participate in this conversation.