Get yesterday's date in year-month-day format?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get yesterday's date in year-month-day format?
# 1  
Old 06-18-2009
Get yesterday's date in year-month-day format?

Dear All,

Actually, i'm doing some reporting job and i need to pass yesterday's date in Year-Month-Day format(e.g. 2009-06-10) to another program for generating 2009-06-10 report.


to get today's date, it's easy to just date '+%Y%m%d' , but no idea how can i get this kind of format for yesterday?

echo "`date '+%Y%m%d'` - 1 " | bc seems not the correct way for this, because it will go wrong on the beginning date of each month.
( e.g. 20090601 - 1 will have problem.)

how about converting the date string in '+%s' format back to '+%Y%m%d' format? is this possible? for instance :
echo "`date '+%Y%m%d'` - 86400" | bc | <command to convert back to regular date format probaby by date command> ?
(86400 = 60 seconds * 60 minutes * 24 hours)

any advice on this? I'm sorry if this makes you confusing...
# 2  
Old 06-18-2009
`date -d "1 day ago" +%y%m%d`
# 3  
Old 06-18-2009
thanks so much for this easy way.

by the way, if i just only have the date '%s' format, is it possible to revert it to the regular date format?

for instance : if we receive a time string like this : 1245375232 , how can we know this is actually 2009/6/19 09:33 ??

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How bash treats literal date value and retrieve year, month and date?

Hi, I am trying to add few (say 3 days) to sysdate using - date -d '+ 3 days' +%y%m%d and it works as expected. But how to add few (say 3 days) to a literal date value and how bash treats a literal value as a date. Can we say just like in ORACLE TO_DATE that my given literal date value... (2 Replies)
Discussion started by: pointers1234
2 Replies

2. Shell Programming and Scripting

Julian day to dates in YEAR-MONTH-DAY

hello, I have many files called day001, day002, day003 and I want to rename them by day20070101, day20070102, etc. I need to do it for several years and leap years as well. What is the best way to do it ? Thank you. (1 Reply)
Discussion started by: Ggg
1 Replies

3. Shell Programming and Scripting

Day before yesterday's date

Hello All, I am writing a script in Sun Solaris I want the date for "day before yesterday", i got the yesterday's date by this command TZ=GMT+24 date +%b" "%d. Please suggest me some code to get the date for day before yesterday (6 Replies)
Discussion started by: anand2308
6 Replies

4. Shell Programming and Scripting

Day of year to dd.mm.yyyy format

Hi, How can I convert day of year value in format(yy,doy) to normal formatted (dd.mm.yyyy) string also all of them with awk or awk system function? in_file.txt --------- 12,043 12,044 12,045 12,046 out_file.txt ---------- 12.02.2012 13.02.2012 14.02.2012 15.02.2012 imagine... (5 Replies)
Discussion started by: kocaturk
5 Replies

5. Shell Programming and Scripting

Help to generate date from day of the year

Hi I want to convert the day of the year(yyyyddd) to date in mmddyy format Example: input is 2005029 --------> 29th day of 2005 I have to get the output as 01292005 ---> jan 29th 2005 I've to do this in K-Shell There were threads that dealt with coverting date to day of the year but I... (3 Replies)
Discussion started by: sudhamayeev
3 Replies

6. AIX

Convert unix timestamp to year month day format ?

Hello, How do I convert unix timestamp value to 'normal' date format - to get year month and day values ? Looks like it's easy to do using GNU date (linux systems). But how do I do tthis on AIX ? I don't want to write C program, any ways to do that using unix shells ? thanks (1 Reply)
Discussion started by: vilius
1 Replies

7. Shell Programming and Scripting

Removing day before yesterday's date

Hi i am having a backup folder wherein i will be having the files ftp ed to remote server, i need to keep only the data of last two days and remove the old log files. how can i achieve this ? i have tried... #!/bin/bash D=`date +'%d'` oldday=`expr $D - 2` rm /sent/data-$oldday* echo... (8 Replies)
Discussion started by: aemunathan
8 Replies

8. Shell Programming and Scripting

Concatenating Files In A Year/Month/Day File Structure

Hi Im trying to concatenate a specific file from each day in a year/month/day folder structure using Bash or equivalent. The file structure ends up like this: 2009/01/01/products 2009/01/02/products .... 2009/12/31/products The file I need is in products everyday and I need the script to... (3 Replies)
Discussion started by: Grizzly
3 Replies

9. Shell Programming and Scripting

yesterday date month/date

Hi expert, I want to retrieve yesterday su log. How to calculate and assign variable value ( 06/23 ) in myVariable ? #!/bin/sh myVariable=yesterday date in month/date cat /var/adm/sulog | grep $myVariable > file.txt many thanks! (5 Replies)
Discussion started by: skully
5 Replies

10. Shell Programming and Scripting

Day of month and year to mmddyyyy

I have a date that looks like this: 2008/100:18:40:47.040 I need it to look like this: 2008 04 09 18 40 47 040 I have looked at datecalc and it doesn't seem like it takes the day of year for this year (or whatever year is input) and converts it into month and day. It also has to account... (2 Replies)
Discussion started by: ajgwin
2 Replies
Login or Register to Ask a Question