Date is a command line utility for printing or setting the date and time.

learn more… | top users | synonyms

45
votes
3answers
5k 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?
23
votes
10answers
3k views

Year 2038 problem

What is the likelihood of the Year 2038 issue being very problematic?
19
votes
5answers
19k 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).
17
votes
3answers
2k 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)?
17
votes
6answers
28k 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 ...
16
votes
9answers
9k 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 ...
15
votes
1answer
415 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: ...
14
votes
4answers
11k 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?
13
votes
3answers
7k views

How can I have `date` output the time from a different timezone?

I have a server running with the timezone 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 ...
12
votes
4answers
6k views

How can I avoid “Run fsck manually” messages while allowing experimenting with system time changes?

I'm working with a system where we want to allow users to play around with the date and time if they want, and where reboots may happen arbitrarily. This is fine, except for one thing: if there's a ...
10
votes
4answers
13k 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 ...
10
votes
2answers
531 views

What is a distro-agnostic way determine the OS install date?

I am on a CrunchBang machine and trying to write a script that needs to have the OS install date as a reference. I searched and found this command: ls -lct /etc | tail -1 | awk '{print $6, $7, $8}' ...
10
votes
3answers
941 views

What is the recommended way to synchronize time using NTP?

This question has come up a number of times in a localized way, this question is meant to provide the preferred/best method for synchronizing a system's clock using NTP. The solution should handle ...
9
votes
2answers
1k views

How can I delete all files in a folder that haven't been accessed in a certain amount of time?

I'd like to run a nightly cron job that deletes all the files in a folder that haven't been accessed in a week or more. What is the most efficient way to do this in bash?
9
votes
3answers
1k views

How to use the date command to find out what date “monday week 40” will be?

How can I use the date command to convert something like "monday week 40" into a ISO date? I am playing with something like this: date --date='monday week 40' +'%Y-%m-%d' And the date I'm ...
8
votes
2answers
662 views

date - years prior to 1901 are treated as invalid

I have date (GNU coreutils) 7.1 installed on my system. If I try to check dates prior to 14-Dec-1901, I get an "invalid date" error. For example, $ date -d 1901-12-13 date: invalid date ...
8
votes
6answers
6k views

date, get current 15 minute interval

Is there any way I can get the current 15 minute interval using the date command or similar ? e.g. something like date %Y.%m.%d %H:%M will give me 2011.02.22 10:19 , I need something that yields ...
8
votes
1answer
3k views

Is there a way to adjust the formatting of the date/time in the GNOME 3 login screen and desktop?

I'm specifically looking to change the formatting in two places: On the desktop, the date/time reads "Sat 21:05". I would like it to read "23-Jul-11 21:05" or "23 Jul 11 21:05". In other words, I ...
7
votes
3answers
521 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 ...
7
votes
3answers
550 views

Forcing an 'added' alias to every command

Is it possible to forcibly add a timing alias (for lack of a better way to phrase it) to every command in bash? For example, I would like to have a specific user who whenever a command is run, it is ...
7
votes
2answers
5k views

How to find difference between two timestamps up to milliseconds?

I am new to shell scripting. The heart of my script is to find the difference between two timestamps up to milliseconds. With me I have a file with content of timestamps only as 2012-09-13 ...
6
votes
4answers
4k views

Renaming a bunch of files with date modified timestamp at the end of the filename?

So, say, I have a directory with a bunch of files like g.txt, where g.txt was last modified on, say, June 20, 2012. How would I batch-rename all of the files (like g.txt) with the last modified date ...
6
votes
2answers
225 views

Batch rename image files by age plus add date and variable to filename

The question is completely rewritten due to things learned from the first two answers and comments that I was unaware of when first asking. After a photo shoot I come home with files that look like ...
6
votes
4answers
8k views

Appending timestamp stamp along with log file lines

I have a log file and I need to append timestamps to each line as they get added. So I'm looking for script that appends timestamps to each entry in log lines and which could run as a cron job. Could ...
6
votes
3answers
658 views

sort at jobs chronologically

Possibly a simple solution I misplaced. How can I get the output of atq sorted chronologically, so I can easily see who's due to run next? The man page for sort doesn't have anything built-in to ...
6
votes
3answers
13k 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 ...
6
votes
4answers
665 views

convert date format in log

I have a log with following date format: 2013-12-14 18:53:33 aaaaaaaaaaaaaaaa 2013-12-14 18:53:33 bbbbbbbbb 2013-12-14 18:53:33 ccccccccccccccccccccc What would be the simplest solution to convert ...
6
votes
2answers
5k views

Good method to compare time?

I need to check for the current time and abort the script if it is not proper time of day I am supposed to run it. Also, if anyone else runs it, it should abort. For example: I need my script to only ...
6
votes
3answers
1k views

Equivalent of date --reference in Solaris

The GNU implementation of the date command has a nice feature to show the date of the last modification of a reference file, and using the +FORMAT parameter it is easy to get the date in any format, ...
6
votes
1answer
159 views

locale definition with French republican calendar

I wonder if it is possible to create a locale definition that would make the C library format the dates according to the French republican calendar. I expect then, for example, run `date' and get ...
6
votes
4answers
702 views

Date computations without GNU tools

I have to perform some date calculations and conversion in a shell script. For example computing the difference in day between a date formatted as Nov 28 20:27:19 2012 GMT and today. There are ...
6
votes
1answer
436 views

In KDE, how can I create a custom keyboard shortcut that prints the current date?

I often need to print the current date in lots of different programs. Right now, I always type it per hand which is error prone. I'm using KDE 4.8, and it has customisable keyboard shortcuts. For ...
5
votes
5answers
2k 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 ...
5
votes
3answers
1k views

Fast way to build a test file with every second listed in YYYY-mm-dd HH:MM:SS format

I want to create a large test file with lines containg dates listed by the second, but my method is taking inordinately long... (or at least, that's how it feels :) ... 43 minutes to create only ...
5
votes
3answers
252 views

How to have command history with timestamps output to the terminal continuously?

I use a simple alias to enable the "tracking" of commands in one or many terminal window(s): alias trackmi='export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"' Then I just tail -f my .bash_history ...
5
votes
1answer
2k views

Removing leading zeros from DATE

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 ...
5
votes
3answers
9k views

Find files which are created a certain time after or before a particular file was created

I need a shell script which finds files which are created 1 hour before or 1 hour after a particular file (test.txt) was created. If I go with find -newer, that means I'd have to create a temporary ...
5
votes
3answers
2k views

Installation date of Ubuntu

How can I determine when Ubuntu was installed in my computer? There was a different question posted here, but none of them is helpful.
5
votes
1answer
1k views

Get “date” to understand a timestamp phrase of a different language

My web-scraping scripts have long enjoyed using date -d to read in human-formatted time and date stamps like "March 11, 1999" and convert to any other format I need via the -s parameter. How might I ...
5
votes
1answer
3k views

Calculate the date from 1125 days ago on non-GNU systems?

On the Unix Bash commandline, I want to calculate the date from 1125 days ago using the base operating system (e.g. No Perl or Python). On systems running GNU Date, I can do something like this: ...
5
votes
1answer
247 views

Remind syntax combining a weekly event with a time range

How should I write "Every Tuesday, Thursday, Friday after 2011 Sep 13, but before Sep 28, with reminder 1 day before event". Now I got REM Tue Thu Fri 13 Sep 2011 +1 UNTIL 28 Sep 2011 MSG Esem, but ...
4
votes
5answers
2k views

Convert formatted dates to seconds since the epoch

I have a file: pablo tty8 Thu Nov 1 12:51:21 2012 still logged in (unknown tty8 Thu Nov 1 12:50:57 2012 - Thu Nov 1 12:51:21 2012 (00:00) pablo tty2 Thu Nov 1 12:50:39 2012 still logged in pablo ...
4
votes
2answers
5k views

How to get elapsed time from two “text based” dates

I would like to know if there is a way to calculate the difference between two times in bash. I have two fields that are extracted from a log file: Start time: Feb 12 10:02:10 End time: Feb 12 ...
4
votes
3answers
2k views

how to suppress bash octal number interpretation? (to be interpreted as decimal)

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 ...
4
votes
2answers
2k views

/etc/shadow date of last password change—UTC or local time?

man 5 shadow gives the following description of the third field in each line: The date of the last password change, expressed as the number of days since Jan 1, 1970. The value 0 has a ...
4
votes
1answer
510 views

How to understand the unix time format?

How does the Unix time format work? For example, the Unix time for 3:00 PM is: Normal time format <----3:00PM = 1402565420----> Unix Time How can I make it understand the time as 3:00 PM ?
4
votes
1answer
86 views

How does coreutil's date manage to get such weird results?

I was playing around with date to try to convert expressions such as "2 hours" to a number of seconds like 7200. I thought I could perform this with invocations such as: date -d "1970-01-01 00:00:00 ...
4
votes
2answers
68 views

Off by 1 year error in GNU date?

Right now, 2014-01-06, GNU date 8.4 on CentOS release 6.4, does this: $ date --date "last week" +"%Y-%V" 2013-01 On the other hand, $ date --date "last week" +"%Y-%U" 2013-52 which is just ...
4
votes
2answers
198 views

How do I find seconds since midnight?

Using the date program, how can I calculate the number of seconds since midnight?
4
votes
4answers
2k views

Convert Unix timestamp into human-readable format on AIX

I need to convert unix timestamp (number of seconds since 1970, e.g. 1381260225 is Tue Oct 8 19:23:45 GMT 2013) into a standard human-readable format. I could get some answers by googling but those ...