Format date string
P粉680087550
2023-08-18 12:54:30
<p>I have this string "0001-01-01T00:00:00.0000000 01:00". </p>
<p>I tried creating a validation rule similar to <code>Y-m-dTH:i:s.uP</code>, but it failed.
What is the correct format of this string? </p>
<pre class="brush:php;toolbar:false;">public function rules()
{
return [
[
['requested_delivery_date'],'datetime', 'format' => 'php: Y-m-dTH:i:s.uP'
],
];
}</pre></p>
According to the time string
0001-01-01T00:00:00.0000000 01:00
, the possible date formats are as follows:YYYY-MM-DD
I'm not sure if the regex will validate it correctly. So, it will be better if you use custom function to validate this date format. Or validate the date, time and time zone separately and concatenate them in your format when saving to the database.