Xdega Posted November 22, 2010 Share Posted November 22, 2010 Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: 11/19 22:23:18.143 Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/ Share on other sites More sharing options...
ManiacDan Posted November 22, 2010 Share Posted November 22, 2010 Use explode or preg_match to grab the bits of the string, and mktime() to construct a timestamp out of the string, then simply use subtraction to get the answer. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138086 Share on other sites More sharing options...
Xdega Posted November 22, 2010 Author Share Posted November 22, 2010 Thanks Manic Dan, Is there any chance you could show me an example? I know I may be a lil dumb. (I am very new to PHP). But I am unsure what you are saying. I guess to clarify further the csv file that I using is about 5mb of text. The first line is as follows: 11/19 22:23:18.143 SPELL_AURA_APPLIED,0x0200000002CA1862,"Chomi",0x10514,0x0200000000EB54DA,"Shasre",0x514,57330,"Horn of Winter",0x1,BUFF and the last line is as follows: 11/19 23:18:45.018 SWING_DAMAGE,0x0200000004EF41E0,"Ponkyy",0x518,0x02000000050469BD,"Croe",0x518,1634,-1,1,0,0,0,1,nil,nil It is basically the time from the server of the game (in this case WoW). I want to build a script that will be able to be used on different files. (depending on what "combat log" is uploaded). As a result the first and last time will most likely always be different. Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138145 Share on other sites More sharing options...
AbraCadaver Posted November 22, 2010 Share Posted November 22, 2010 Might come in handy: http://us.php.net/manual/en/function.sscanf.php Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138150 Share on other sites More sharing options...
ManiacDan Posted November 22, 2010 Share Posted November 22, 2010 More accurately, you probably want fgetcsv Once you have the timestamp in a string, you need to use explode to break it into its parts. You will have to use explode multiple times. Then, once you have the parts, you will use mktime[/code] to make a timestamp out of the parts. Once you have the timestamp representing the log file time, use time and subtract to get the difference. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138156 Share on other sites More sharing options...
Xdega Posted November 22, 2010 Author Share Posted November 22, 2010 oh ok cool. Makes a bit more sense now. Basically I am already using fgetcsv() and pulling the data in to an array. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138169 Share on other sites More sharing options...
AbraCadaver Posted November 23, 2010 Share Posted November 23, 2010 You can actually convert that to a time this year and convert it to whatever format you want (depends on what you need): $time = date('h:i:s', strtotime($csv[0])); Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138475 Share on other sites More sharing options...
Xdega Posted November 23, 2010 Author Share Posted November 23, 2010 oh wow, that looks much cleaner. Just what I am looking for. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/219504-calculate-time-in-seconds-based-on-time-stamp/#findComment-1138480 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.