jim2281950 Posted June 4, 2021 Share Posted June 4, 2021 My script reports the time with a six minute error added to the current time. I can't figure out why. I wrote a different script for solar calculation and get a 7 minute error subtracted. I'm hoping a response to this post will help me solve both problems. I abbreviated the six minute error script to simplify the problem. ===================================================== date_default_timezone_set("America/New_York"); $date = new DateTime(); $date4 = new DateTime(); echo(date("Y-m-d H:i:s"))." date\n"; $now = new DateTime(); $timestring = $now->format('Y-m-d H:i:s'); echo($timestring)." timestring\n"; $date2=date_create(date("y-m-d")); $date4=date_create(date("y-m-d")); date_add($date,date_interval_create_from_date_string("0 Hours")); date_add($date4,date_interval_create_from_date_string("06 Hours")); echo date_format($date2,"Y-m-d, H:m:s")." date2\n"; echo date_format($date4,"Y-m-d, H:m:s")." date4\n"; ======================================================= Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/ Share on other sites More sharing options...
requinix Posted June 4, 2021 Share Posted June 4, 2021 Have you already checked that the server time is correct? Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587001 Share on other sites More sharing options...
jim2281950 Posted June 4, 2021 Author Share Posted June 4, 2021 (edited) Yes. I ran : echo(date('d-m-y h:i:s'))." = current date"; The correct result: 04-06-21 10:39:58 current date I think the problem originates in the following command: $start = date_add(date_create(),date_interval_create_from_date_string("6 hours")); Edited June 4, 2021 by jim2281950 Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587003 Share on other sites More sharing options...
jim2281950 Posted June 4, 2021 Author Share Posted June 4, 2021 (edited) Correction: The problem code: $date4=date_create(date("y-m-d")); date_add($date4,date_interval_create_from_date_string("06 Hours")); echo date_format($date4,"Y-m-d, H:m:s")." date4\n"; Edited June 4, 2021 by jim2281950 Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587004 Share on other sites More sharing options...
requinix Posted June 4, 2021 Share Posted June 4, 2021 10 minutes ago, jim2281950 said: echo date_format($date4,"Y-m-d, H:m:s")." date4\n"; What does "m" mean? Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587005 Share on other sites More sharing options...
jim2281950 Posted June 4, 2021 Author Share Posted June 4, 2021 (edited) 'Y-m-d' - months and 'H:m:s' - minutes. I added '0 minutes 0 seconds' to the format string with no change in the result. I tried 'print' in addition to 'echo', with no change in the result. Edited June 4, 2021 by jim2281950 Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587006 Share on other sites More sharing options...
Solution requinix Posted June 4, 2021 Solution Share Posted June 4, 2021 So if I tried to format as "mmm", what would it do? Months? Minutes? Combination of both? Check the documentation, or look up earlier in your code to see what you should be using instead. Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587007 Share on other sites More sharing options...
jim2281950 Posted June 4, 2021 Author Share Posted June 4, 2021 I wondered why the 'i' was used. Thought that was an option and 'm' was interpreted by context. Changing to 'i' solved the problem. Thanks requinix. Quote Link to comment https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/#findComment-1587008 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.