Jump to content

6 minute error in date-times


Go to solution Solved by requinix,

Recommended Posts

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";

=======================================================

Link to comment
https://forums.phpfreaks.com/topic/312854-6-minute-error-in-date-times/
Share on other sites

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 by jim2281950
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.