Precise calculation between 2 dates and times in UnixTimestamp
Hi, it's been a while. I've been racking my brain for a few days with a classic XYZ problem, and honestly I ran out of ideas.
I need to calculate the difference between 2 dates and times and return the value to me in unixtimestamp, for example the difference in Unix between now and Friday 14:00PM, but honestly I'm unsuccessful in this. That's what's left after several attempts, the days return correctly, but I'm in doubt as to how to proceed with the calculation of hours to be an exact value. PHP Code:
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Use parse_time to convert both the start and end date time strings to unix timestamps. Then subtract these 2 values and you'll get the difference in seconds, which seems to be what you want.
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Quote:
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Does this help?
PHP Code:
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Quote:
Edit: And that made me have an idea of what to do, I will use part of my stock with part of yours, so I take how many days are left until the required date, and I use parse_time, thanks. |
Re: Precise calculation between 2 dates and times in UnixTimestamp
I guess I do not fully understand what you are trying to do. Can you explain a real world example?
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Quote:
PHP Code:
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Explaining in code isn't ideal, just explain in words.
Example: "I want my plugin to tell players how much time away it currently is from 7/4/21, and then again 1 week later" |
Re: Precise calculation between 2 dates and times in UnixTimestamp
Quote:
|
Re: Precise calculation between 2 dates and times in UnixTimestamp
Ok, it's a lot simpler then if I understand correctly. format_time() can do most of the work for you, see http://cplusplus.com/reference/ctime/strftime/
PHP Code:
|
| All times are GMT -4. The time now is 02:33. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.