Visit Our UNIX and Linux User Community

Shell Scripting Date manipulation

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Scripting Date manipulation
# 1  
Old 07-16-2013
Shell Scripting Date manipulation

Hi Experts,

i have date as inputdate=01/01/2013,how to get the previous date from this date and also first day's date of the month.





how can i get solution to this. my unix is not supporting GNU Dates


Last edited by Scott; 07-16-2013 at 08:40 AM.. Reason: Another continuation of a previous thread (bump) and no code tags. Closed.

Previous Thread | Next Thread
Test Your Knowledge in Computers #145
Difficulty: Easy
Unix popularized the hierarchical file system with arbitrarily nested subdirectories, originally introduced by Multics.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the consecutive last 10 week day date using UNIX ksh shell scripting?

Hi, i am writing a ksh shell script to check the last month end date whether it is falling in last 10 week day date, I am not sure How to use "Mr. Perderabo's date calculator", Could you Please let me know how to use to get my requirement, I tried my own script but duplicate week day and... (5 Replies)
Discussion started by: karthikram
5 Replies

2. Shell Programming and Scripting

Stream manipulation in UNIX shell scripting

i have a file something like this : start: 01:00:00 01:30:00 02:30:00 05:30:00 end: 01:13:00 02:00:00 02:40:00 05:45:00 and i want (end - start) total run time in below format: run: 00:13:00 00:30:00 00:10:00 00:15:00 (4 Replies)
Discussion started by: Acme
4 Replies

3. Shell Programming and Scripting

AIX Scripting for File Manipulation

Hi, Totally newbie in scripting. And need helps in preparing a script to help me to do file moving, renaming and even delete. I have 2 directories. 1. /FTP/new 2. /FTP/backup Scenario a) I will be getting new text files (e.g NewFile23052013.txt) created in the directory #1 every day... (1 Reply)
Discussion started by: quickerz
1 Replies

4. Shell Programming and Scripting

Shell Scripting: Copy Files with Today's date

I was wondering the best way about finding files that were created today and copy them to a directory (grep ?). There can be multiple files for todays date or none. I am looking to copy all of the .lis files for todays date. I may need to modify the filename to include todays date but for the... (4 Replies)
Discussion started by: smkremer
4 Replies

5. Shell Programming and Scripting

Date Manipulation

I have a file with a field containing the following: "7/3/2009 7:07:12 PM","xxxx" I need to be able to split this field up into two into a different format with the time being converted into 24 hour: so that i can get the following: "20090307","19:07:12","xxxx" (8 Replies)
Discussion started by: Pablo_beezo
8 Replies

6. Shell Programming and Scripting

Shell scripting string manipulation

Hi, if I have a string delimited by commas how can I put each character on a new line followed by a carriage return, and output this to a filee.g from: s,t,r,i,n,g to s t r i n g thanks you (3 Replies)
Discussion started by: Wahmed9
3 Replies

7. Shell Programming and Scripting

Scripting neophyte needs file manipulation assistance

I need to write two shell scripts for an rsync backup solution. The first script will copy all backed up files into a folder named after the original folder, plus a date stamp (so e.g. if the original folder name is 'foo' and is backed up on the 10th of September, then the backup folder will be... (0 Replies)
Discussion started by: LambdaCalculus
0 Replies

8. Shell Programming and Scripting

date manipulation

HI, I'm comparing my file date with the system date and if both the dates are equal I'm doing some operation. I use two variables for these two dates. I use the following command in my query. if .... But here the current date $cd shows 01 and filedate $fdate shows 1. The file is created on 1 of ... (6 Replies)
Discussion started by: pstanand
6 Replies

9. Shell Programming and Scripting

Manipulation of Date in Shell

Reuirement: I have a set of files ina diectory which has the name in format "WWW-YYYYmmDD" like, WWW-20070226. for 26th FEB 2007. Now I need to write a shell script which should move the files to directory named "old" in the same directory if date attached to file is 90 days prior to today's... (1 Reply)
Discussion started by: jnanesh.b
1 Replies

10. Shell Programming and Scripting

Date format - Shell scripting gurus please help

Guys: I have the following script (from this forum) to calculate yesterdays date. However the format of the date that is output is yyyymd if the resultant date is single digit or the resultant month is a single digit month ( 01 - 09 ). How can I get the output to show the date in the following... (3 Replies)
Discussion started by: geomonap
3 Replies
date(1) 						      General Commands Manual							   date(1)

       date - print date and time

       date [-c | -u] [ +format ] [[yy[mm[dd]]]hhmm[.ss][-[-]tttt][z]]

       If no argument is given, or if the argument begins with +, the current date and time are printed.  Otherwise, the current date is set.  The
       first mm is the month number; dd is the day number in the month; hh is the hour number (24 hour clock); the second mm is the minute number;
       .ss  the second; -[-]tttt is the minutes west of Greenwich; a positive number means your time zone is west of Greenwich (for example, North
       and South America) and a negative number means it is east of Greenwich (for example Europe); z is a one letter code indicating the dst cor-
       rection mode (n=none, u=usa, a=australian, w=western europe, m=middle europe, e=eastern europe); yy is the last 2 digits of the year number
       and is optional.  The following example sets the date to Oct 8, 12:45 AM:
       date 10080045
       The current year is the default if no year is mentioned.  The system operates in GMT.  The takes care of the conversion to and  from  local
       standard and daylight time.

       If  the	argument begins with +, the output of is under the control of the user.  The format for the output is similar to that of the first
       argument to All output fields are of fixed size (zero padded if necessary).  Each field descriptor is preceded by % and is replaced in  the
       output by its corresponding value.  A single % is encoded by %%.  All other characters are copied to the output without change.	The string
       is always terminated with a new-line character.

       -c     Perform operations using Coordinated Universal Time (UCT) instead of the default local time. The UCT does not use  leap  seconds	so
	      UCT is the same as GMT.

       -u     Perform operations using Greenwich Mean Time (GMT) instead of the default local time.

       + format
	      The following is a list of field Descriptors that can be used in the format (Note: date exits after processing format information) :

		 %a   Locale's abbreviated weekday name

		 %A   Locale's full weekday name

		 %b   Locale's abbreviated month name

		 %B   Locale's full month name

		 %c   Locale's date and time representation

		 %d   Day of month as a decimal number (01-31)

		 %D   Date (%m/%d/%y)

		 %h   Locale's abbreviated month name

		 %H   Hour as a decimal number (00-23)

		 %I   Hour as a decimal number (01-12)

		 %j   Day of year (001-366)

		 %m   Number of month (01-12)

		 %M   Minute number (00-59)

		 %n   Newline character

		 %p   Locale's equivalent to AM or PM

		 %r   Time in AM/PM notation

		 %S   Second number (00-59)

		 %t   Tab character

		 %T   Time (%H/%M/%S)

		 %U   Week number (00-53), Sunday as first day of week

		 %w   Weekday number (0[Sunday]-6)

		 %W   Week number (00-53), Monday as first day of week

		 %x   Locale's date representation

		 %X   Locale's time representation

		 %y   Year without century (00-99)

		 %Y   Year with century

		 %Z   Timezone name, no characters if no timezone

		 %%   %

       The following command line
       date +%m/%d/%y
       generates the following output
       The following command line
       date +"DATE: %m/%d/%y%nTIME: %H:%M:%S"
       generates the following output
       DATE: 04/02/89
       TIME: 14:45:05
       The quotes (") are necessary because the format contains blank characters. Use single quotes (') to prevent interpretation by the shell.

       Failed to set date: Not owner
	    You are not the super-user and you tryed to change the date.  Do not change the date while the system is running in multiuser mode.

       An attempt to set a date to before 1/1/1970 will result in the date being set to 1/1/1970.



Featured Tech Videos