Getting date -1 day not using GNU date


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Getting date -1 day not using GNU date
# 1  
Old 04-08-2011
Getting date -1 day not using GNU date

It's easy as pie to get the date minus one day on opensolaris:
Code:
date -d "-1 day" +"%Y%m%d"

run this command on our crappy Solaris 10 machines however (which I'm guessing doesn't have GNU date running on it) and you get:
Code:
date: illegal option -- d
date: illegal option -- 1
date: illegal option --
date: illegal option -- d
date: invalid argument -- y
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

This is so so annoying. I can't put GNU date on these unix machines, so how can I get the date -1 day?

Cheers

---------- Post updated at 01:37 PM ---------- Previous update was at 01:21 PM ----------

nevermind... this does it...

Code:
DATE_STAMP=`TZ=UTC+24 date +%y%m%d`; echo $DATE_STAMP


Last edited by Yogesh Sawant; 04-09-2011 at 08:02 AM.. Reason: corrected a typo in the subject
# 2  
Old 04-08-2011
Tricky, using the time stamp in hours! However, the problem is you used the Solaris date, not the GNU/LINUX date. You can get trusted Solaris binaries or source and configure/make your own GNU utilities. Solaris may even have them on their CDs now, since I saw them a lot. You may have them in /usr/local/bin or some such place not high enough on your $PATH.

ksh93 and bash have date operations built-in.
# 3  
Old 04-08-2011
See my datecalc script.
# 4  
Old 04-08-2011
Or my tm2tm C program, anything +- anything to anything, give or take some integer overflow. https://www.unix.com/shell-programmin...bsd-linux.html
# 5  
Old 04-08-2011
Quote:
ksh93 and bash have date operations built-in.
Humm, I do not think that bash has date operations builtin other than printf %T integer formatting option.
# 6  
Old 04-11-2011
Sorry, it was inconceivable to me that ksh93 did things that bash could not! Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. Shell Programming and Scripting

Date: invalid date trying to set Linux date in specific format

i try to set linux date & time in specific format but it keep giving me error Example : date "+%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" or date +"%d-%m-%C%y %H:%M:%S" -d "19-01-2017 00:05:01" keep giving me this error : date: invalid date ‘19-01-2017 00:05:01' Please use CODE tags... (7 Replies)
Discussion started by: umen
7 Replies

3. Shell Programming and Scripting

Calculate given date - 1 day

Hi Team, We have a requirement as follows. If a date 20141220 as parameter to the script, then the script has to return the output as 20141219. i.e given date - 1. The requirement is simple. But it should satisfy leap year, the months having 31 and 30 days, the date in which day light... (9 Replies)
Discussion started by: kmanivan82
9 Replies

4. AIX

Need to get the next day's date of the user entered date

I need to get the next day's date of the user entered date for example: Enter date (yyyy/mm/yy): 2013/10/08I need to get the next day's date of the user entered date Desired Output: 2013/10/09Though there are ways to achieve this is Linux or Unix environment (date command) ,I need to... (1 Reply)
Discussion started by: rpm120
1 Replies

5. Shell Programming and Scripting

Date to Day in loop

Hi All, I have a file in the following format.I need to pick up 25th field which is a date and convert it into a day and add it as a field in the file. "AAGENAS,PEARL... (3 Replies)
Discussion started by: nua7
3 Replies

6. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

7. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

8. Shell Programming and Scripting

how to obtain date and day of the week from `date` command

Hi, does anybody know how to format `date` command correctly to return the day of the week? Thanks -A I work in ksh.... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Dummies Questions & Answers

date - 1 day

Hi, I have been trying just about every unix command to come up with yesterday's date (today's date - 1). I have seen all of the help on this forum, and none of it seems to work for me here. We are using Sun Solaris 9 Unix. I am using this script to create a .txt file with ftp commands that I will... (2 Replies)
Discussion started by: sfedak
2 Replies

10. Shell Programming and Scripting

Getting day from a date...

Hi, I have a date input in MMDDYYYY format.. I have to give the day (whether that DD is sunday/monday...) Is there any command for it... Or do I have to write a script for that... Thanks in Advance Yeheya (1 Reply)
Discussion started by: yeheyaansari
1 Replies
Login or Register to Ask a Question