Questions tagged [date]
the "date" tag is used to classify questions about date/calendar/time manipulation, visualisation, conversion... on Unix-like systems.
1,161
questions
1845
votes
3
answers
435k
views
Why does man print "gimme gimme gimme" at 00:30?
We've noticed that some of our automatic tests fail when they run at 00:30 but work fine the rest of the day. They fail with the message
gimme gimme gimme
in stderr, which wasn't expected. Why are we ...
285
votes
12
answers
431k
views
How do I convert an epoch timestamp to a human readable format on the cli?
How do I convert an epoch timestamp to a human readable format on the cli? I think there's a way to do it with date but the syntax eludes me (other ways welcome).
215
votes
5
answers
202k
views
date command --iso-8601 option
This answer and comments mention --rfc-3339 and a "hidden" --iso-8601 option that I have used for a long time and now seems to be undocumented.
When did that option documentation get removed from the ...
195
votes
5
answers
438k
views
How do I add X days to date and get new date?
I have Linux ( RH 5.3) machine
I need to add/calculate 10 days plus date so then I will get new date (expiration date))
for example
# date
Sun Sep 11 07:59:16 IST 2012
So I need to get
...
185
votes
7
answers
299k
views
How can I have `date` output the time from a different time zone?
I have a server running with the time zone set to UTC. It seemed like that was generally a good practice (please correct me if I'm wrong).
Anyhow, one of the servers I connect to, in order to scp ...
183
votes
3
answers
712k
views
Timezone setting in Linux [closed]
I'm setting the timezone to GMT+6 on my Linux machine by copying the zoneinfo file to /etc/localtime, but the date command is still showing the time as UTCtime-6. Can any one explain to me this ...
150
votes
15
answers
424k
views
How to compare two dates in a shell?
How can two dates be compared in a shell?
Here is an example of how I would like to use this, though it does not work as-is:
todate=2013-07-18
cond=2013-07-15
if [ $todate -ge $cond ];
then
...
137
votes
18
answers
302k
views
Quickly calculate date differences
I often want to make some quick date calculations, such as:
What is the difference between these two dates?
What is the date n weeks after this other date?
I usually open a calendar and count the ...
133
votes
5
answers
217k
views
last time file opened
Is it possible to get the time when file was opened last time and sort all files in a directory by those times?
124
votes
4
answers
117k
views
Day of week {0-7} in crontab has 8 options, but we have only 7 days in a week
Day-of-week: Allowed range 0 – 7. Sunday is either 0 or 7.
I found this after Googling, my question is why should both values (0,7) correspond to Sunday?
116
votes
7
answers
587k
views
Linux: set date through command line
How to change the system date in Linux ?
I want to change:
Only Year
Only Month
Only Date
Any combination of above three
105
votes
7
answers
182k
views
Show the year while listing files in the current directory
I am working on a Red Hat server. The commands ls -l or ll giving me the date and time in format +"%b %-d %H:%M".
I want to list the files in a way where the year when each was file created would ...
80
votes
9
answers
320k
views
How to append date to backup filename
I need to make a backup of a file, and I would like to have a timestamp as part of the name to make it easier to differentiate.
How would you inject the current date into a copy command?
[root@...
72
votes
9
answers
179k
views
How do I set time and date from the Internet?
How do I retrieve the date from the Internet and set my computer's clock, from the command line?
71
votes
5
answers
299k
views
Appending a current date from a variable to a filename
I'm trying to append the current date to the end of a file name like this:
TheFile.log.2012-02-11
Here is what I have so far:
set today = 'date +%Y'
mkdir -p The_Logs &
find . -name The_Logs -...
67
votes
1
answer
101k
views
How do you time how long a command took to run? [duplicate]
How would you find out how long a running process took to complete?
Example:
date; dd bs=1m if=/foo of=bar; date
^This example only has 1 second of resolution.
Any shell is acceptable.
66
votes
3
answers
241k
views
How do you put date and time in a file name?
I'm trying to execute a command and would like to put the date and time in the output file name.
Here is a sample command I'd like to run.
md5sum /etc/mtab > 2016_4_25_10_30_AM.log
The date time ...
66
votes
1
answer
228k
views
Date time in Linux bash [closed]
I am trying to display a date time in the form of
07/08/2013 16:52:13
by using command in bash script:
dt=`date '+%d/%m/%Y_%H:%M:%S'`
which variable is used to populate a CSV file.
The only char ...
65
votes
4
answers
50k
views
Removing leading zeros from date output
I made an alias of the date command to display date in the following format:
2013.06.14.12.10.02
using this command:
alias date = date +"%Y.%m.%d.%H.%M.%S"
Everything works great, except I want ...
51
votes
1
answer
125k
views
How to get the current date and time in YYYYMMDDHHMMSS format in ksh88?
My requirement is to get difference of 2 timestamps in hours.
As the date diff option is taking long for me to figure out I am trying to convert both dates in to YYYYMMDDHHMMSS format and find the ...
48
votes
4
answers
138k
views
List of Recently Modified Files
How can I Get a list of all files modified , say 3 months ago.
I checked this question but I was not able to apply it to my scenario.
I am trying this now , it seems to be working , but I know there ...
43
votes
4
answers
28k
views
How do I remove leading zeroes from output of 'date' or avoid octal interpretation of such decimal numbers?
I have this:
date +"%H hours and %M minutes"
I use festival to say it up.. but it says like: "zero nine hours".. I want it to say "nine hours"!
but date always give me 09... so I wonder if bash can ...
40
votes
2
answers
71k
views
Can date format current time for GMT timezone? [duplicate]
When I run date +"%Y%m%d%H%M%S" I receive 20171225203309 here in CET time zone.
Can I use date to obtain a the current time in the same format, but for timezone GMT?
38
votes
7
answers
57k
views
What is a standard command for printing a date in RFC-3339 format?
The date command doesn't offer such thing, which is kind of sad since RFC-3339 is the modern, widespread, sane format used everywhere (except in email which is neither modern nor sane).
My timezone ...
38
votes
4
answers
61k
views
get elapsed time in bash
I would like to do the following at one point in a script:
start_time=date
and this after a process or processes have run:
end_time=date
and then do this:
elapsed=$end_time-$start_time
echo "...
35
votes
3
answers
84k
views
How does the "1 month ago" option in date command work?
I'm not sure if this gets the past date within the current day or if it only takes 30 or 31 days to it.
e.g.
If the current date is March 28th, 1 month ago must be February 28th, but what happen ...
34
votes
1
answer
5k
views
Error message "date: invalid date '2016-10-16'"
Today my clock was automatically adjusted to summer time, and a script from a crontab started failing. I had a look at what was happening, and the following error was being displayed, with LC_ALL=C:
...
32
votes
5
answers
276k
views
Display time stamp in dd/mm/yyyy_hh:mm:ss:ms in Unix or Linux
I need to display date and time in desired format in Unix/ Linux. My desired format is:
dd/mm/yyyy hh:mm:ss:ms in Unix or Linux. I got close using the following command:
echo $(date +%x_%r)
This ...
31
votes
5
answers
33k
views
"date -d" command fails on Docker Alpine Linux container
I built Alpine Linux in a Docker container with the following Dockerfile:
FROM alpine:3.2
RUN apk add --update jq curl && rm -rf /var/cache/apk/*
the build run successfully:
$ docker build -...
31
votes
4
answers
23k
views
Why does TZ=UTC-8 produce dates that are UTC+8?
The current time in Los Angeles is 18:05. But when I run TZ=UTC-8 date --iso=ns, I get:
2013-12-07T10:05:37,788173835+0800
The date utility tells me that the time is 10:05, and even says that it's ...
31
votes
5
answers
35k
views
How to list files sorted by modification date recursively (no stat command available!)
How can I get the list of all files under current directory along with their modification date and sorted by that date?
Now I know how to achieve that with find, stat and sort, but for some weird ...
30
votes
3
answers
27k
views
How do you specify a format for the input to date?
Given a date and time in a format that is not recognized by date, how can I get date to recognize the date and time?
For example:
$ date -d "09SEP2012:23:58:46"
date: invalid date `09SEP2012:23:58:...
28
votes
5
answers
39k
views
Subtract time using date and bash
All the other questions on the SE network deal with scenarios where either the date is assumed to be now (Q) or where only a date is specified (Q).
What I want to do is supply a date and time, and ...
28
votes
5
answers
62k
views
Getting all files that have been modified on a specific date
Is it possible to find all php files within a certain directory that have been modified on a certain date
I'm using
find /var/www/html/dir/ -mtime -28 | grep '\.php'
to get files modified within ...
28
votes
1
answer
7k
views
How to trick a particular command into thinking it is a different date?
How can I execute a command making it believe that is on a different date than system one?
For instance, if I have this script:
#!/usr/bin/env bash
date +"%B %d, %Y"
It prints the actual date: ...
27
votes
9
answers
6k
views
Year 2038 problem [closed]
What is the likelihood of the Year 2038 issue being very problematic?
27
votes
1
answer
2k
views
Why is `TZ=Asia/Kolkata date --date="1/1/1906"` invalid?
When I run:
TZ=Asia/Kolkata date --date="1/1/1906"
I get:
date: invalid date ‘1/1/1906’
Here I can find a good article on that:
Calcutta Time
But the confusion also comes from the fact ...
26
votes
3
answers
3k
views
How can I shutdown a RHEL server at 06:45 tomorrow morning?
I just received notification that our site has a power outage tomorrow morning.
I am a Windows admin but I have to cover for our Linux admin who's not around until tomorrow evening.
I need to ...
25
votes
11
answers
25k
views
Tool in UNIX to subtract dates
Is there any tool in Solaris UNIX (so no GNU tool available) to subtract dates? I know that in Linux we have gawk that can subtract one date from another. But in Solaris the maximum we have is nawk (...
25
votes
1
answer
4k
views
Best practice to customize date/time format system-wide?
TL;DR
What is the best practice for customizing my date and time format settings, while sticking to the DRY-principle, i.e. without repeating stuff unnecessarily?
I'd like to customize exclusively ...
24
votes
7
answers
80k
views
How to check if the current time is between 23:00 and 06:30
I am having trouble grasping how to properly check from a bash script if the current time is between 23:00 and 06:30.
I am trying to run an infinite loop to check the time now, and to do something if ...
23
votes
4
answers
11k
views
Change time (date) in or from exif data
In the question Change file created date from JPEG EXIF metadata there are great scripts to update the file system date and to match date stored in the file. But what if the “Date and Time (original)” ...
22
votes
3
answers
25k
views
Find out exact installation time of CentOS
I installed CentOS on my laptop about 8 month ago, and
I want to know when exactly I installed it , how can I do that in CentOS 6.4 ?
21
votes
2
answers
4k
views
Date Command Gives Wrong Week Number for Dec 31
When I try to get the week number for Dec 31, it returns 1. When I get the week number for Dec 30, I get 52 --- which is what I would expect. The day Monday is correct. This is on a RPI running Ubuntu....
21
votes
7
answers
55k
views
How to format date output with spaces as variable in script?
I want to make the date command with nice formatting like this:
$ date +"%Y-%m-%d %H:%M:%S"
2015-09-17 16:51:58
But I want to save this in variable, so I could call from script like this:
echo "$(...
20
votes
3
answers
6k
views
How does touch -t work internally?
How does touch -t command works exactly, internally (I tried to find its source code but couldn't)?
20
votes
3
answers
3k
views
What's the POSIX-compliant way to get the epoch timestamp in a shell?
I just noticed, that POSIX date doesn't seem to have the %s or %N format items. So I can't use those. What's an alternative, yet POSIX-compliant way to get the epoch timestamp in my shell script?
19
votes
7
answers
10k
views
Convert Unix timestamp to human-readable time
I would like to view a text file with awk/grep which contains a Unix timestamp in the first column.
How can I convert it to a human-readable time while viewing?
19
votes
2
answers
99k
views
How to get current month name in bash script
What is the syntax to get the current month name (e.g. jan or feb) in a bash script?
19
votes
5
answers
39k
views
How to parse ISO8601 dates with linux date command
I'm trying to use the date command to generate a file timestamp that the date command itself can interpret. However, the date command does not seem to like its own output, and I am not sure how to ...