0
votes

suppose i have one column in mysql database which is stated last time one equipment is up in h:i:s format (ex: 00:05:11) or 1d21h, means that the equipment is on since 5 min before, what is the best method i can convert this to unix timestamp, say if using php script how? or direct convert last unix timestamp using mysql function query.

actually, i want to calculate for start time for this equipment uptime in unix timestamp where i have one column in mysql startcapture that will be deducted with last column to get start time. so starttime = startcapture - last (this last time that has to convert to unix timestamp based on now() - h:i:s ). but the problem is sometimes the format change from h:i:s to ex: 1d22h, if h:i:s means the equipment is up since ex: 00:05:11 min before and if 1d22h means the equipment already up 1 day 22 hours before.

so the main things here is to convert last column to appropriate unix timestamp.

please help guys, asap.

update:

simplified like this,

i want to display the start time, that can only be calculate by deducting startcapture column with last column,

startcapture column in unix timestamp, while the last column in h:i:s format sometimes in 1d22h format (means the equipment is already up since 1 day 22 hour or since 00:05:11, hours minute seconds)

the only things I want is to convert last column into unix timestamp which is time() - (00:05:11 or 1d22h),

is there any specific function?

1
Why are you storing relative times from now in the database? What happens if time all of the sudden for some reason decides to move forward?Ignacio Vazquez-Abrams
Plus, your description is very detailed but a bit hard to understand. Can you make a concrete example with actual numbers?Pekka
all the data are grabbed from the router, the script is written by my colleague, the management wants the report ASAP, so I can't think of any other solution...Nazrul Muhaimin
pekka, i will update my questionNazrul Muhaimin

1 Answers

1
votes

If you have the time parsed into variables then you can use mktime to get the timestamp: http://www.php.net/manual/en/function.mktime.php