Date Stamp -1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date Stamp -1
# 1  
Old 12-22-2005
Date Stamp -1

I need to move files after midnight but attach the previous date to it.

Moving files before midnight no proproblem but how can I move files which are created on the 22nd for example but add a date stamp of previous day?

Date ='date +"Y%m%d"' gets today's date but how can I get yesterday's date.


Thanks
# 2  
Old 12-22-2005
there is a datecal program by perderabo on the forum. Search for that. I havent personally used as I never had a need to so far. But have read thru the forums so many times and all praises for it Smilie. So go ahead and use it. Here is the link

https://www.unix.com/unix-for-dummies-questions-and-answers/4870-days-elapsed-between-2-dates-post16559.html#post16559
# 3  
Old 12-23-2005
Use the following script to get previous day's date.

#! /usr/bin/ksh
# Get yesterday's date in YYYY-MM-DD format.
# With argument N in range 1..28 gets date N days before.

OFFSET=${1:-1}

case $OFFSET in
*[!0-9]* | ???* | 3? | 29) print -u2 "Invalid input" ; exit 1;;
esac

eval `date "+day=%d; month=%m; year=%Y`
typeset -Z2 day month
typeset -Z4 year

# Subtract offset from day, if it goes below one use 'cal'
# to determine the number of days in the previous month.
day=$((day - OFFSET))
if (( day <= 0 )) ;then
month=$((month - 1))

if (( month == 0 )) ;then
year=$((year - 1))
month=12
fi

set -A days `cal $month $year`
xday=${days[$(( ${#days[*]}-1 ))]}
day=$((xday + day))
fi
print $year-$month-$day
# 4  
Old 12-23-2005
Computer date -1

simply just try :
date -d -1day
date -d -1day '+%Y%m%d'
date -d yesterday '+%Y%m%d'

Last edited by onimalu; 12-23-2005 at 04:27 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Date stamp on thread postings.

Is it possible to have the actual date shown, instead of phrases like "1 Week Ago", on threads list of postings? If possible, how do I enable that? (0 Replies)
Discussion started by: Svenus
0 Replies

2. Shell Programming and Scripting

Files with date and time stamp

Hi Folks, Need a clarification on files with date and time stamp. Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS". Now i need to check for this file and if it is available then i need to do some task to the file. I tried... (6 Replies)
Discussion started by: jayadanabalan
6 Replies

3. Shell Programming and Scripting

writing condition using date stamp

Hi all, I am writing a script which i am executing using nohup command. while ( true ) do RequiredTime=06:00:00 SysTime=`echo $(date) | awk '{print $4}'` if ]; then body of script fi done this is executing 3 times at 6am. i want it execute the body of script... (3 Replies)
Discussion started by: firestar
3 Replies

4. UNIX for Dummies Questions & Answers

How to Zip the files from date Stamp to end date Stamp

Hi, I need to zip the list of files using from date Stamp to end date Stamp, How can I filter and make FromDate_EndDate.gzip? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

5. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies

6. Shell Programming and Scripting

Date Stamp on new file

Dear Gurus, I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script: #! /bin/csh Today_Date=`date +%Y%M%D` mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date} when i run the script i'm getting the following errors: mv:... (14 Replies)
Discussion started by: lweegp
14 Replies

7. Shell Programming and Scripting

creating a new file with date stamp

Hi, can any one tell me how to achieve this...I will input the path and file name and it should rename it to current date and time... this is what I tried... #! /usr/bin/sh set -x cd /info_stg/vul/Scripts TODAY_DATE_TIME=`date +%Y%m%d%H%M%S` IN_FILE_PATH=`cat file.txt | awk -F, '{... (2 Replies)
Discussion started by: mgirinath
2 Replies

8. Shell Programming and Scripting

Insert Time and Date Stamp

I have a directory with following files in it ABC.000.DAT ABC.001.DAT ABC.002.DAT ABC.003.DAT I want to insert time and date stamp in file names like ABC.000.YYYYMMDDHHMM.DAT I able to insert the time and date stamp at the end of filename Kindly help (1 Reply)
Discussion started by: aajmani
1 Replies

9. Shell Programming and Scripting

Date Time Stamp

I'm trying to write a script that checks the DTS of a file the compares it to the current time. If greater that 60 mins has gone by and the file has not been written to alert. So far I have the time pulled from the file but I dont know how to compare the times against a 60 min difference. ... (2 Replies)
Discussion started by: jarich
2 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question