Display date from twelve hours ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display date from twelve hours ago
# 1  
Old 07-22-2013
Display date from twelve hours ago

HI Guys

I want to create date folder in unix base on currant date minus 12 hours.

Ex:

Code:
Currant date :07222013 and time is 1 Am


So the folder will create date :07212013


Last edited by Scott; 07-22-2013 at 10:29 PM.. Reason: Spelling fixes
# 2  
Old 07-22-2013
What is your OS and version?
# 3  
Old 07-22-2013
In Linux:
Code:
gacanepa@Gabriel-PC ~ $ uname -a
Linux Gabriel-PC 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Using GNU Bash:
Code:
gacanepa@Gabriel-PC ~ $ bash --version
bash --version
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.

This does the trick:
Code:
mkdir $(date +%m%d%Y -d "12 hours ago")

Otherwise, you can get the job done using perl (available out-of-the-box in most Unix flavors):
Code:
gacanepa@Gabriel-PC ~ $ mkdir $(perl -e 'print scalar localtime( time - 43200 ) . "\n";' | date +%m%d%Y)

# 4  
Old 07-23-2013
Code:
#/bin/bash
#purpose of this code is to display past time, as per this system clock in IST timings
arg=$1
echo $(date +%Y%m%d%H%M%S -d "$arg hours ago")
echo

Run this code as below

Code:
-bash-4.1$ ./past_date 12
20130722225318



here , 12 is passed as runtime parameter.The script can give output for any dynamic number entered by user.

Last edited by vinil; 07-23-2013 at 02:30 AM..
# 5  
Old 07-23-2013
Still Not Work :

Code:
p14515f@glne2cx1> (date +%m%d%Y -d "100 hours ago" )
07232013

# 6  
Old 07-23-2013
You are not referencing the hours in the date command options. What do you actually expect to get out of it and what are you trying to do? You are asking it to display MonthDayFullyear, so I'm lost as to where 12 hours comes in.


Robin
# 7  
Old 07-25-2013
Quote:
Originally Posted by pareshkp
Still Not Work :

Code:
p14515f@glne2cx1> (date +%m%d%Y -d "100 hours ago" )
07232013

Code:
#/bin/bash
#purpose of this code is to display past time, as per this system clock in IST timings
arg=$1
echo $(date +%Y%m%d%H%M%S -d "$arg hours ago")
echo
-bash-4.1$

you had missed what i have highlighted

and what you tried gave me following results
Code:
-bash-4.1$ date +%m%d%Y -d "100 hours ago"
07212013

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to display processes which have been running for more than a X hours?

Hi, Is it possible to display processes which have been running for more than a 5hrs using a variation of the ps -ef command? Regards, Manny (5 Replies)
Discussion started by: mantas44
5 Replies

2. Shell Programming and Scripting

Get a given date and subtract it to 5 days ago

Hi all, I have been researching to obtain SSL certification expiry for most of our webistes. For some cases, some hosts where not directly accessible so i finally got a solution working with curl using my proxy. This lists the expiry date which i'm finally looking for. # curl --proxy... (4 Replies)
Discussion started by: nms
4 Replies

3. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

4. Homework & Coursework Questions

list of files modified 10 hours ago using grep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is the question: Make a list of files in your home directory that were changed less that 10 hours ago,... (3 Replies)
Discussion started by: fight4love
3 Replies

5. Shell Programming and Scripting

Date One Week Ago From Given Date, Not From Current Date

Hi all, I've used various scripts in the past to work out the date last week from the current date, however I now have a need to work out the date 1 week from a given date. So for example, if I have a date of the 23rd July 2010, I would like a script that can work out that one week back was... (4 Replies)
Discussion started by: Donkey25
4 Replies

6. Shell Programming and Scripting

Date within a timeframe 2 days ago

How could I using the following example, change it to show 2 days ago within the same time frame 0600 AM to 0600 AM let foo=`date "+(1%H-106)*60+1%M-100"` bar=foo+1440 find . -mmin +$foo -mmin -$bar | tr -s '/','-' '^' | cut -f2,3 -d"^" | tr -s '^' ' ' | Please use code tags (7 Replies)
Discussion started by: freddie999
7 Replies

7. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

8. Shell Programming and Scripting

find a date two weeks ago?

Anyone got a script or suggestion for this? I want to find the date when a parameter in days is supplied.. ie.. parameter can be any number for example 15... and the date returned should then be 15 days ago... or 31 and the date returned should be 31 days ago... Any ideas on best way to... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question