SunQuest
           Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb Site ManagementScripts

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 27th, 2004, 09:03 AM
bluwulf bluwulf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 105 bluwulf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 33 m 28 sec
Reputation Power: 5
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:

my_date=`TZ=EST-24 date` # where date is the system's date (assume that date returned Mon Oct 25 15:51:18 EST 2004)

echo $my_date # my_date returns Tue Oct 26 20:53:08 EST 2004


# Each time I subtract 24 the date is incremented


(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 ?

Reply With Quote
  #2  
Old November 3rd, 2004, 06:33 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,077 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 13 h 40 m 11 sec
Reputation Power: 8
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();

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Is there a way (in the Korn Shell) to accurately increment a date ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway