time comparing problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: time comparing problem (/showthread.php?tid=87592) |
time comparing problem - anuragk - 05-08-2023 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. RE: time comparing problem - InsiteFX - 05-08-2023 PHP DateTime: Create, Compare and Format Dates Easily RE: time comparing problem - anuragk - 05-09-2023 (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? RE: time comparing problem - iRedds - 05-12-2023 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. RE: time comparing problem - anuragk - 05-13-2023 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 RE: time comparing problem - kenjis - 05-13-2023 Time::parse() takes a string as a first parameter. https://codeigniter4.github.io/CodeIgniter4/libraries/time.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. RE: time comparing problem - demyr - 05-13-2023 What I use and works: PHP Code: $now = date('Y-m-d H:i:s'); I get minutes as result RE: time comparing problem - anuragk - 05-13-2023 (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/libraries/time.html?highlight=time#comparing-two-times |