Sponsored Content
Top Forums UNIX for Advanced & Expert Users fetch dates for last 36 days in format yyyy-mm-dd Post 302358245 by sunilk1303 on Thursday 1st of October 2009 07:36:06 PM
Old 10-01-2009
heres a simple way:-
Code:
#!/bin/ksh
set -x
i=1
 while [ $i -le 5 ]; do
date -d "`date +%Y`-01-01 +$(( `date +"%j"` - $i ))days" +%Y-%m-%d
i=`expr $i + 1`
echo $i
done

i have used a simple trick to convet the current calender date into julian date, substract it by 1, and convert back it to the calendar date Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

2. Shell Programming and Scripting

Date difference between 2 dates in 'yyyy-mm-dd hh:mm:ss' format

Hi all, I know this may have already been asked but hey ho... i have two dates in the 'yyyy-mm-dd hh:mm:ss' format. '2009-01-03 01:00:00' '2009-04-05 00:00:00' How can i, in shell script determine their differences? Please note, the time may not be available, so please suggest both... (4 Replies)
Discussion started by: muay_tb
4 Replies

3. Shell Programming and Scripting

Sed: zero-padding dates (or: convert d/m/yyyy to dd/mm/yyyy)

Hi all I have some pipe-separated data in the form: 5/12/2008 00:00:00|31/1/2009 00:00:00|SOMESTUFF|OTHERSTUFF 12/31/2008 00:00:00|15/1/2009 00:00:00|MORESTUFF|REMAININGSTUFF 1/1/1023 00:00:00|16/5/2047 00:00:00|THEREST|YETMORE I need to zero-pad the single-digit days and months, using... (3 Replies)
Discussion started by: jgrogan
3 Replies

4. Shell Programming and Scripting

change date format from yyyy/mm/dd to dd/mm/yyyy

(Attention: Green PHP newbie !) I have an online inquiry form, delivering a date in the form yyyy/mm/dd to my feedback form. If the content passes several checks, the form sends an e-mail to me. All works fine. I just would like to receive the date in the form dd/mm/yyyy. I tried with some code,... (6 Replies)
Discussion started by: keyboarder
6 Replies

5. Shell Programming and Scripting

Need date in the format [mm dd yyyy hh AM/PM]

could you please help be on the below code .. Requirement is when i pass the parameter(for below 2) i should get current time -2 hours in the format :wall:.. cur_dt=`$ICEBIN/sqsh -S$DSQUERY -U $BATCHID -P $PASSWD -h -C"select getdate()" | sed '2d'` pr_dt="`$ICEBIN/sqsh -S$DSQUERY -U $BATCHID... (2 Replies)
Discussion started by: karthicss
2 Replies

6. Shell Programming and Scripting

age in months for yyyy-mm-dd format

Hi, I am trying to write a sh script which will give difference in given time to present time in months. I get date from a script like infoscript.sh | awk '{ print $3}' where infoscript is a custom script and gives date in yyyy-mm-dd format ex: 2010-04-12 Now, need to do... (8 Replies)
Discussion started by: rider29
8 Replies

7. Shell Programming and Scripting

Fetch data between two dates from a file

Hi All, I m new to this forum & UNix too. currently i have a requirement which can fetch data from a logfile between two dates or timestamp. for example: 1. data from 2012 Jun to 2012 Jul 2. data from 2012 Jun to 2012 Jul 07 3. data from 2012 Jun 16 10:20 to 2012 Jul 03 10:10 Please... (7 Replies)
Discussion started by: KDMishra
7 Replies

8. Shell Programming and Scripting

Date Format MM/DD/YYYY

I am changing epoch times to dates. I was able to do the following: echo "$varx" | gawk '{print strftime("%c", $0)}' Mon Dec 31 16:26:40 2012 This changes the epoch date (which is what varx is) into localtime. However, my problem is that I only want 12/31/2012 and not the Mon Dec 31... (2 Replies)
Discussion started by: newbie2010
2 Replies

9. Shell Programming and Scripting

Fetch the last two days directory names and rename them

Hi All, I have below directory structure and from these directories, I would like to fetch the last two days list of directories and append a '0' (zero) to those directories. bash-4.1$ ls -lrt total 32 drwxr-xr-x+ 6 root root 9 Sep 5 01:05 tested-597 drwxr-xr-x+ 6 root root 9 Sep 9... (3 Replies)
Discussion started by: ibad_urs
3 Replies

10. Shell Programming and Scripting

Date format YYYY/MM/DD to DD/MM/YYYY

I am getting output of YYYY-MM-DD and want to change this to DD/MM/YYYY. When am running the query in 'Todd' to_date(column_name,'DD/MM/YYYY') am getting the required o/p of DD/MM/YYYY, But when am executing the same query(Netezza) in linux server(bash) am getting the output of YYYY-MM-DD file... (3 Replies)
Discussion started by: Roozo
3 Replies
Calendar::Simple(3pm)					User Contributed Perl Documentation				     Calendar::Simple(3pm)

NAME
Calendar::Simple - Perl extension to create simple calendars SYNOPSIS
use Calendar::Simple; my @curr = calendar; # get current month my @this_sept = calendar(9); # get 9th month of current year my @sept_2002 = calendar(9, 2002); # get 9th month of 2002 my @monday = calendar(9, 2002, 1); # get 9th month of 2002, # weeks start on Monday my @span = date_span(mon => 10, # returns span of dates year => 2006, begin => 15, end => 28); DESCRIPTION
A very simple module that exports one function called "calendar". calendar This function returns a data structure representing the dates in a month. The data structure returned is an array of array references. The first level array represents the weeks in the month. The second level array contains the actual days. By default, each week starts on a Sunday and the value in the array is the date of that day. Any days at the beginning of the first week or the end of the last week that are from the previous or next month have the value "undef". If the month or year parameters are omitted then the current month or year are assumed. A third, optional parameter, start_day, allows you to set the day each week starts with, with the same values as localtime sets for wday (namely, 0 for Sunday, 1 for Monday and so on). date_span This function returns a cur-down version of a month data structure which begins and ends on dates other than the first and last dates of the month. Any weeks that fall completely outside of the date range are removed from the structure and any days within the remaining weeks that fall outside of the date range are set to "undef". As there are a number of parameters to this function, they are passed using a named parameter interface. The parameters are as follows: year The required year. Defaults to the current year if omitted. mon The required month. Defaults to the current month if omitted. begin The first day of the required span. Defaults to the first if omitted. end The last day of the required span. Defaults to the last day of the month if omitted. start_day Indicates the day of the week that each week starts with. This takes the same values as the optional third parameter to "calendar". The default is 0 (for Sunday). This function isn't exported by default, so in order to use it in your program you need to use the module like this: use Calendar::Simple 'date_span'; EXAMPLE A simple "cal" replacement would therefore look like this: #!/usr/bin/perl -w use strict; use Calendar::Simple; my @months = qw(January February March April May June July August September October November December); my $mon = shift || (localtime)[4] + 1; my $yr = shift || (localtime)[5] + 1900; my @month = calendar($mon, $yr); print " $months[$mon -1] $yr "; print "Su Mo Tu We Th Fr Sa "; foreach (@month) { print map { $_ ? sprintf "%2d ", $_ : ' ' } @$_; print " "; } A version of this example, called "pcal", is installed when you install this module. Date Range This module will make use of DateTime.pm if it is installed. By using DateTime.pm it can use any date that DateTime can represent. If DateTime is not installed it uses Perl's built-in date handling and therefore can't deal with dates before 1970 and it will also have problems with dates after 2038 on a 32-bit machine. EXPORT "calendar" AUTHOR
Dave Cross <dave@mag-sol.com> ACKNOWLEDGEMENTS
With thanks to Paul Mison <cpan@husk.org> for the start day patch. COPYRIGHT
Copyright (C) 2002-2008, Magnum Solutions Ltd. All Rights Reserved. LICENSE
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl, localtime, DateTime perl v5.10.1 2010-04-02 Calendar::Simple(3pm)
All times are GMT -4. The time now is 05:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy