time comparing problem |
I am trying to compare two times on the same day.
Code: $myTime = Time::now('Asia/Kolkata', 'en_US'); // get the current date and time Code: if i remove local one more problem is that even after midnight today, means after 12:00:00 AM the if block works which is not supposed to work because the date is changed.
PHP DateTime: Create, Compare and Format Dates Easily
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-08-2023, 10:00 PM)InsiteFX Wrote: PHP DateTime: Create, Compare and Format Dates Easily Do you mean I need to use other approaches than the one in the CI guide?
It is not known what the "current" time is. Maybe it's more than 15:00:00
time::parse(); does not convert time to time zone.
The problem was with Time::parse, if we don't pass the locale it will automatically convert the time to the default locale
so no matter where you convert the time while parsing you need to pass the locale. for ex. Code: $myTime = Time::now('Asia/Kolkata', 'en_US'); // get the current date and time
Time::parse() takes a string as a first parameter.
https://codeigniter4.github.io/CodeIgnit...e.html#now The string value for the time object does not have timezone. So the default timezone is used if you don't specify a timezone as the second parameter of Time::parse(). By the way, why do you need to parse the Time object? It has already the current time.
What I use and works:
PHP Code: $now = date('Y-m-d H:i:s'); I get minutes as result (05-13-2023, 07:40 PM)kenjis Wrote: Time::parse() takes a string as a first parameter. as suggested by your user guide, I parse time so I can compare two times. Code: <?php https://www.codeigniter.com/user_guide/l...-two-times |
Welcome Guest, Not a member yet? Register Sign In |