- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Playing with date..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2007 07:32 PM
тАО10-30-2007 07:32 PM
Playing with date..
I have some requirements with date. Based on TODAY and YESTERDAY, need to calculate the date variables. Which will be passed as an argument to the database.
If today is Thursday Oct 25, 2007:
Requirements.
Value Maestro parm and meaning
TODAY = today ( today's date )
YESTERDAY = Yesterday .
$YESTERDAY < 1 DAY = day before yesterday
$YESTERDAY < 2 days = 2 days before yesterday (3 days ago)
$YESTERDAY < 6 DAYS = 6 days before yesterday
$YESTERDAY < 7 DAYS = 7 days before yesterday
$YESTERDAY < 20 DAYS = 20 days before yesterday
$YESTERDAY < 30 DAYS = 30 days before yesterday
$YESTERDAY < 60 DAYS = 60 days before yesterday
$YESTERDAY < 90 DAYS = 90 days before yesterday
$YESTERDAY < NEAREST FIRSTDAY = the nearest first day of month before yesterday
$TODAY < 1 MONTH < NEAREST FIRSTDAY = the nearest first day of the month before 1 month ago
$YESTERDAY < 6 MONTH < NEAREST FIRSTDAY = the nearest first day of the month before 6 months ago
$YESTERDAY < 12 MONTH < NEAREST FIRSTDAY = the nearest first day of the month before 1 year ago
$YESTERDAY < 24 MONTH < NEAREST FIRSTDAY = the nearest first day of the month before 2 years ago
$TODAY < NEAREST LASTDAY = the nearest last day of the month before today
$TODAY < 1 MONTH < NEAREST LASTDAY = the nearest last day of the month before 1 month ago
$TODAY < 1 MONTH > NEAREST LASTDAY = the nearest last day of the month after 1 month ago
$YESTERDAY > 14 DAYS = 14 days forward from yesterday
Is there any better way to write a script or function to archive this.
Sridhara.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2007 11:49 PM
тАО10-30-2007 11:49 PM
Re: Playing with date..
Use Perl;
To obtain dates in the past or the future, you can simply do:
# perl -MPOSIX -le '$days=shift or die;print strftime "%m/%d/%Y",localtime(time-$days*86400)' 1
10/30/2007
...or yesterday (one day ago).
The 'strftime' formatting directives can be found in the standard manpages so you can craft your output according to your taste.
The above code can also be made to calculate future dates:
# perl -MPOSIX -le '$days=shift or die;print strftime "%m/%d/%Y",localtime(time-$days*86400)' -- -1
11/01/2007
THe double dash says that no options follow and thus the '-1' is treated as the argument we want.
You will find the Perl 'Date::Calc' module quite useful for more complicated calculations.
Regards!
...JRF...
Pass the
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-30-2007 11:51 PM
тАО10-30-2007 11:51 PM
Re: Playing with date..
Is the above specification a fixed given, or can you use something caljd uses?
If i were to have to solve a problem like stated i would grab PERL and check out Time::Timelocal and localtime (sp) between them you can create and work with an array of time elements (month-day, month).
That make it easy to calculate the time corresponding with the first of the month, the firs of last month and so on. Switch to the time in seconds to subtrace days (24*60*60 = 86400 seconds / day)
It's work, but not unpleasant.
Cheers,
Hein.
- Tags:
- caljd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2007 06:46 PM
тАО11-05-2007 06:46 PM
Re: Playing with date..
Find the attached solution.
Rgds
-NKG-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-05-2007 07:08 PM
тАО11-05-2007 07:08 PM
Re: Playing with date..
To go back more than one day, get_one_day_before_specified_date must be called N times.
Some slight improvements can be made:
if [ $intmonth -eq 01 ]; then
intmonth=12
Not needed since checked in "then" block.
intmonth=`expr $intmonth - 1`
Can be done with: (( intmonth -= 1 ))
${AWK} 'NF != 0{ last = $0 }; END{ print last }' | ${AWK} '{ print $NF }'
Can be done with one awk:
${AWK} 'NF != 0 { last = $NF }; END{ print last }'
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-07-2007 11:26 PM
тАО11-07-2007 11:26 PM
Re: Playing with date..
If you have found a solution, please assign points and close this thread. Thanks!
http://forums1.itrc.hp.com/service/forums/helptips.do?#28
Regards!
...JRF...