|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Is there a way (in the Korn Shell) to accurately increment a date ?
Is there a way (in the Korn Shell) to accurately increment a date ?
Say for example that I awk out the following "start_date" and "end_date" (in the format below) from a file: start_date = 10/25/2004 end_date = 11/12/2004 How do I increment from the start_date to the end_date ? (also note the change in months for the dates it is also possible that the years could be different) I wuz given an example like this though : Quote:
(The above seem to work but I don't really understand it) For my purposes I could very well work with this "solution"....except for the little problem that the dates that I would be feeding the script would look like : 10/26/2004 NOT Tue Oct 26 20:53:08 EST 2004 Is there a way to convert 10/26/2004 TO Tue Oct 26 20:53:08 EST 2004 ********************************************** I have re-evaluated what is it I am really trying to acomplish and have come up with somewhat of a different algorithm for what is it I really want to do. This is what I am trying to do : I have a file withg some information (which is uniformly arranged) like this: F1 F2 F3 F4 F5 F6 (Currently) I am only intrested in intrested in feilds F2 F4 and F6. All feilds are separated by a single space. Where F4 and F6 are the start and end dates respectively. Now I have a directory called my_dir. In my_dir I have directories named after years. So in my_dir I have (may have) directories called 2001, 2002, ...2004, 2005..... In each of thoze directories I have directories named after the months. SO in the 2004 directory I have directories : Jan, Feb, Mar, Apr, May,....Dec In each of thoze (month) directories I have directores named after the days of a month. So I have directories 01, 02, 03, 04.....31 NOTE that each month directory have directories corresponding to 31 days even if the month does not have 31 days (example the Feb directory) Each of these (day) directory contains (lots and lots of) files. I need to seach theze files Before I go any further lets return to this : F1 F2 F3 F4 F5 F6 Feild F4 and F6 gives me the start_date and the end_date. Thus I kno which directories to start the search in and where to end the search. In searching the files I need to extract all lines in each file (within the specified ranges) that start with feild F2 My (initial) solution I would simply extract the start_date and end_date and simply extract the info (starting at the start_date ) and continually incrementing the start date up the end_date. That could work for start_date = 10/25/2004 (format is: mm/dd/yyyy) end_date = 10/29/2004 That method doesn't work for this though : start_date = 09/25/2004 (format is: mm/dd/yyyy) end_date = 10/29/2004 NOTE the difference in months. So obviously I couldn't simply increment the start_date to the end_date So my new method to deal with this is to increment the start_date to 31 (which may or may not exist for the month) And then reset the star_date (because I am now entering a new month) to 01 then increment from 01 to the end_date. But then a little other problem came up. Suppoze: start_date = 12/25/2003 (format is: mm/dd/yyyy) end_date = 01/29/2004 NOTE the difference in year. I figuer I would approach this the same way I approach the month problem. What do you think ? |
|
#2
|
|||
|
|||
|
i did not really read your Q, but
i mean the stupidest format you can use is 'mm/dd/yyyy' to write a prog interpreting that format is a big deal. something like: yyyymmdd is a little better you can compare it arithmetically. NOTA: yyyy is a 4 digits, mm && dd are 2 digits now you can use a stupid 'if' (in every languages) assumed date is yyyymmdd mindate is what ever you want, but the same format maxdate (see above) if(date >mindate && maxdate >date) dothejob(); |
| Viewing: Dev Shed Forums > Web Site Management > Scripts > Is there a way (in the Korn Shell) to accurately increment a date ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|