Jump to content

Pesky timestamps


Traces

Recommended Posts

I am trying to compare two timestamps in a log file to calculate the time between them, however the timestamps in the log file are in military time and don't include actual dates or anything else.  The problem is that if the log file isn't written to every single hour (out of my control when it will be) or the system is shut off for a while and turned back on I can't compare them if it falls between 2300 hours and 0100 hours for example or 2300 hours one day and 2300 hours the next.  The php file will be checking them at random as well.

[code][23:12:01] Entry
[01:20:56] Entry[/code]

Is there even a solution to this?  It seems unix timestamps is the solution in most of the search results I saw but I don't see how it will work for me here.
Link to comment
Share on other sites

The only problem is it still doesn't tell me whether or not the log file was last updated a day or even a week ago for example.  Also, if I am reading that right that would still give me issues as 2300 hours turned into seconds gives me a higher number than 1000 hours still.

Thinking about it some more though I just realized that I could tell it that if the first number (23:12:01) in my example is larger than the second entry (01:20:56) to simply count backwards...  I am going to test this theory and see where that gets me.

I still don't see how I am going to get over the issue of it "finding its bearings" as it will never (seemingly) be able to tell the difference between 2300 hours of last year to today without something extra to go off of.

Thanks Timbo.
Link to comment
Share on other sites

It is a good thing that 2300 hours turned into seconds is higher than 1000 hours turned into seconds as that is the case in the hours format as well. 

Simply subtract as follows:  23 * 3600 - 10 * 3600 = number of seconds difference.

If you don't know what day these timestamps occurred on, there is no real way to find out unless they happen [b]at least[/b] once a day, wich may or may not be the case. 

But if they do, then detecting if one is less than the other would work.
Link to comment
Share on other sites

I can't see a solution to you being able to compare the two entries because as you say all you have to work with is times and no dates. 

If the file is writen to sequentially then chances are the second entry time is closer to the present than the first entry time. 

Thats about all the information you can get from it.  No way of telling, that I can think of, if the second time is the same day, the next day or the next week.  Only indication of the second time being not the same day would be if the second time is earlier than the first.

I had an idea of maybe checking the log file with filemtime() to get the last time the file was edited, but all that will tell you is the date/time the last entry was added to the log file.  That would still leave you with the problem of figuring out a date for the first entry to compare the two dates.

What level of access do you have to the log file creation?  i.e do you have a say in what format to save the date/time to the log file?  If so I would suggest the date/time, for future entries to include date and time in some format.  Sorry I can't be of more help.
Link to comment
Share on other sites

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.