Questions tagged [date]

the "date" tag is used to classify questions about date/calendar/time manipulation, visualisation, conversion... on Unix-like systems.

Filter by
Sorted by
Tagged with
1845 votes
3 answers

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 ...
Jaroslav Kucera's user avatar
285 votes
12 answers

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).
xenoterracide's user avatar
215 votes
5 answers

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 ...
Angelo's user avatar
  • 2,159
195 votes
5 answers

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 ...
user avatar
185 votes
7 answers

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 ...
cwd's user avatar
  • 44.6k
183 votes
3 answers

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 ...
Rahul Dhobi's user avatar
  • 2,037
150 votes
15 answers

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 ...
Abdul's user avatar
  • 1,691
137 votes
18 answers

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 ...
daniel kullmann's user avatar
133 votes
5 answers

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?
student's user avatar
  • 17.9k
124 votes
4 answers

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?
Ruban Savvy's user avatar
  • 8,439
116 votes
7 answers

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
SHW's user avatar
  • 14.5k
105 votes
7 answers

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 ...
WAEL's user avatar
  • 1,509
80 votes
9 answers

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@...
spuder's user avatar
  • 17.7k
72 votes
9 answers

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?
Mohsen's user avatar
  • 2,515
71 votes
5 answers

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 -...
I AM L's user avatar
  • 873
67 votes
1 answer

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.
spuder's user avatar
  • 17.7k
66 votes
3 answers

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 ...
visc's user avatar
  • 796
66 votes
1 answer

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 ...
Henry's user avatar
  • 827
65 votes
4 answers

Removing leading zeros from date output

I made an alias of the date command to display date in the following format: 2013. using this command: alias date = date +"%Y.%m.%d.%H.%M.%S" Everything works great, except I want ...
easl's user avatar
  • 1,978
51 votes
1 answer

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 ...
xGen's user avatar
  • 643
48 votes
4 answers

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 ...
GoodSp33d's user avatar
  • 595
43 votes
4 answers

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 ...
Aquarius Power's user avatar
40 votes
2 answers

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?
Drux's user avatar
  • 547
38 votes
7 answers

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 ...
Martin Jambon's user avatar
38 votes
4 answers

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 "...
Oliver Williams's user avatar
35 votes
3 answers

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 ...
tachomi's user avatar
  • 7,382
34 votes
1 answer

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: ...
admirabilis's user avatar
  • 4,652
32 votes
5 answers

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 ...
Hank's user avatar
  • 349
31 votes
5 answers

"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 -...
BBJ3's user avatar
  • 981
31 votes
4 answers

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 ...
Alex Henrie's user avatar
31 votes
5 answers

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 ...
alex's user avatar
  • 7,113
30 votes
3 answers

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:...
Cory Klein's user avatar
  • 18.4k
28 votes
5 answers

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 ...
confetti's user avatar
  • 1,892
28 votes
5 answers

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 ...
Elitmiar's user avatar
  • 509
28 votes
1 answer

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: ...
Lucio's user avatar
  • 1,267
27 votes
9 answers

Year 2038 problem [closed]

What is the likelihood of the Year 2038 issue being very problematic?
8128's user avatar
  • 405
27 votes
1 answer

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 ...
15 Volts's user avatar
  • 1,979
26 votes
3 answers

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 ...
user4166144's user avatar
25 votes
11 answers

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 (...
jyz's user avatar
  • 657
25 votes
1 answer

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 ...
0xC0000022L's user avatar
  • 16.2k
24 votes
7 answers

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 ...
Unpossible's user avatar
23 votes
4 answers

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)” ...
Werner's user avatar
  • 231
22 votes
3 answers

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 ?
Alireza Fallah's user avatar
21 votes
2 answers

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....
George Shafer's user avatar
21 votes
7 answers

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 "$(...
gilbertasm's user avatar
20 votes
3 answers

How does touch -t work internally?

How does touch -t command works exactly, internally (I tried to find its source code but couldn't)?
syntagma's user avatar
  • 12.2k
20 votes
3 answers

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?
finefoot's user avatar
  • 2,980
19 votes
7 answers

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?
TheRojam's user avatar
  • 313
19 votes
2 answers

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?
Hiraman Patil's user avatar
19 votes
5 answers

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 ...
alex.forencich's user avatar

2 3 4 5