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

learn more… | top users | synonyms

4
votes
3answers
2k views

Need to get the difference between two time in seconds

The following two variables contain the start time and the end time , need to get the difference between these two time in seconds start_time=06:07:25 end_time=07:02:08 Desired Output diff_time= ...
22
votes
5answers
26k 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).
0
votes
2answers
37 views

append time to log filenames

I want to make log_files named as log_Jan_01_hh:mm:ss, so the variable time-stamp is defined as date +"%b_%d_%T". Now if I set the value to a variable: setenv now `date +"%b_%d_%T"` Then $now ...
4
votes
3answers
108 views

How to append a date to all files in a directory without touching sub-directories via bash script

I'm currently taking a class for Operating Systems and we're learning to do bash scripts as part of the curriculum. I need to append the date to all the files in a directory without touching ...
1
vote
1answer
61 views

How do I put a time stamp with: wget --output-file=[FILENAME] [URL]

So I've been trying to put a timestamp on some images I'm downloading from a webcam, but so far it's been saving the images with the names camera3_date' here's my line that I enter: wget ...
2
votes
6answers
10k views

Extract date from a variable in a different format

Let me explain you the problem $ date +%c -d "$d" Tue 31 Dec 2013 01:13:06 PM CET $ date +'Today is %F' -d "$d" Today is 2013-12-31 This solution corresponds to current date. But I have one ...
1
vote
3answers
104 views

Date in milliseconds on OpenWRT on Arduino YUN

I am using OpenWRT on the Arduino YUN and I am trying to get the exact date in milliseconds (DD/MM/YYYY h:min:sec:ms) by getting the time by an timeserver. Unfortunately date +%N just returns %N, but ...
4
votes
5answers
4k views

Next day of the user entered date - date +1 day

I am new to scripting I needed a script in the AIX environment to get the next days date based on the date entered by the user of the script. After hard time browsing for this I got a piece of code ...
2
votes
2answers
39 views

Get time for system default timezone

When logging in to remote machine X, by default, date will give the time in the local timezone: $ date Mon Nov 17 22:45:47 CET 2014 Note that TZ is not set: $ export | grep TZ $ So, I set TZ to ...
0
votes
2answers
44 views

Can't use argument in bash date calculation script

The following bash script won't work. I need to calculate the date depending on the number of days since 14th Oct 1582, where the argument will be the number of days. d="$1" date -d '14 Oct 1582 + ...
2
votes
1answer
27 views

Append same timestamp to multiple filenames

I have several files that I ftp each hour. The receiving system needs to have some sort of identifier that they came from the same batch, so I would like to append a timestamp to the filename. That ...
1
vote
4answers
42 views

Sort datetime string in 12-hour format

I have a log file with contents like this: 11-12-2014 - 03:03:59AM lat = 41.990516; lon = -93.430704<br> 11-12-2014 - 03:05:15AM lat = 41.001546; lon = -93.443352<br> 11-12-2014 - ...
1
vote
4answers
117 views

How to subtract two times in shell

I nee to subtract two lines which is in the format of time in shell. Th time format is hh:mm:ss I used the code below to get the time. cat /var/log/kern.log |grep usb |tail -2| awk '{print $3}' The ...
0
votes
1answer
44 views

Why can't my `date` deal with timezones? [duplicate]

I'm having some weird issues with GNU coreutils date v8.4 (CentOS) that aren't occurring in v8.21 (Ubuntu/Mint). On v8.4, I get the following output (I'm in PST): $ date --version | head -n 1 date ...
2
votes
1answer
96 views

Leap seconds and date

I've just discovered that Unix time does not include the leap seconds. I think it's quite surprising because doing that, it is slowly diverging from UTC... but that's not the point of my question. ...
1
vote
2answers
82 views

How to get proper format from date for the touch -A argument?

I would like to change all of the attribute times of some files to the immediate date. It appears that I would need to use touch -A * (more or less; realizing that I am going to use a more complex ...
1
vote
2answers
56 views

How to convert time from local timezone into Sydney timezone using korn shell?

I need to convert time from localtimezone (CET/CEST) to Sydney timezone (AEDT/AEST). I tried something like this: export date=$(date "+%Y-%m-%d %H:%M:%S AEDT") date "+%Y-%m-%d %H:%M:%S %Z" -d "$date" ...
1
vote
1answer
45 views

How to enter date as an option in a bash command? [duplicate]

I want to enter the current date (ideally in the form YYYY-MM-DD hh:mm) as an option in a bash script: I tried /usr/local/bin/growlnotify -t "PMK" -m date but then the variable -m inserts the ...
0
votes
1answer
76 views

How to run commands on a variable containing a date?

I need to be able to take a date in the format of "MM/DD/YY" and change it back into the default date format (Fri Oct 31 17:23:07 CDT 2014). This is driving me crazy. The code below may look ...
5
votes
1answer
36 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 ...
3
votes
3answers
220 views

How do I find a file with a name which depends on the current date (and a random component)?

I have to check a particular path every day and find the file with a name of the form: StaticData_Sets_yyyymmdd-232550.txt The date in the name after the string StaticData_Sets_ is updated every ...
2
votes
1answer
84 views

date command, going back one or two days. Seeing different flags

I'm writing a bash script that should run on OSX and Ubuntu. I'm not sure if this particular problem is due to an OS mismatch; more likely it's a difference in the date command on the two shells, ...
1
vote
4answers
130 views

Increment a date in a file

I have a file with single line of text inside.How can I modify its content without using the vi editor.Below is the example: PROCESS DATE =2014-08-01 I want to increment the "2014-08-01" by the ...
8
votes
4answers
636 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 ...
2
votes
3answers
109 views

get list of months using dseq from dateutils

how'd I get a listing of the months in the year (abbreviated) using dseq from dateutils? NOTE simply running: dseq 'jan' 'dec' -i '%b' -f '%b' returns a humongous list of months: piping the ...
3
votes
6answers
5k views

Trying to set date on a Linux based machine from another machine

I am running busy box on an embedded platform. I would like to set the date on the box properly each time I reboot the hardware. I have no way to save the time persistently, so am reduced to setting ...
3
votes
9answers
3k views

How to generate a year-quarter date from the command line?

I'm interested in outputting a representation of the current year-quarter, as well as the year-quarter for the previous month. If today is 2012 January 1st, I'd like to get 2012q1 and 2011q4 as ...
2
votes
1answer
43 views

Where is using @ before a date string for seconds since the epoch documented?

GNU date and touch commands (and presumably others) use @date to define a date string as seconds since the epoch. For example: $ TZ=UTC date -d@10 Thu Jan 1 00:00:10 UTC 1970 I was answering a ...
2
votes
4answers
8k views

First and last day of a month

Given two numbers, month and year, how can I compute the first and the last day of that month ? My goal is to output these three lines: month / year (month in textual form but that is trivial) for ...
2
votes
2answers
52 views

Regarding getting Date - n days Date

Suppose I have a particular date stored in a variable (date_m) . I want ((date_m)-25) date. For eg: I have 15/09/2014 stored in my variable , then I want 21/08/2014 returned if I subtact 25 from the ...
3
votes
1answer
68 views

Save lines to different files based on the date

How can I force a re-evaluation of this each time? cat > $(date '+%H-%M-%S').log So that when I first output something it gets written to one file, and after a few seconds I make another ouput ...
2
votes
3answers
2k 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
2
votes
1answer
6k views

Read log file between two dates

I have to read log file between and my question is how to get only the text in the file wich is between two dates using unix commands? Every line contain date and I want to get the text in the file ...
0
votes
1answer
80 views

Change the timezone in a terminal

I connect my web server via SSH Terminal on Mac. cat /var/www/vhosts/example.com/statistics/logs/error_log The Date of my server and local computer differs so output of error_logs is not efficient ...
2
votes
3answers
100 views

Convert a number of seconds elapsed to date from arbitrary start date

I want to convert a particular amount of seconds to a date. In my case the it's the number of seconds elapsed since 1st of January 0001. If it were for seconds elapsed from epoch it would be easy: $ ...
4
votes
4answers
14k views

Appending current date to 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 ...
16
votes
9answers
10k 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 ...
0
votes
1answer
165 views

Backing up files which were modified after the last backup was run

I am working on a backup script (bash shell - Fedora - VMware) that should compare a file with last modified attribute and current date and should back it up if the last modified date is older than ...
4
votes
2answers
750 views

Local Account Creation Date

For compliance purposes there is the need to fetch information regarding local (user and non-user) accounts creation date on UNIX machines. Is there any way (even if it's not the most reliable or ...
3
votes
3answers
101 views

Parsing arbitrary natural language dates under BSD

I'm using the GNU date command to parse arbitrary natural language dates - for example to detect if a certain epoch time stamp is from last week, I can do: if [ "$timestamp" -lt "$(date +"%s" -d ...
1
vote
1answer
106 views

Setting System Timezone based on a timestamp

I want to set the system date and timezone based on a string that looks like this (output of Javascript new Date().toString()): Fri Aug 01 2014 12:13:27 GMT+0200 (CEST) The standard way to set ...
1
vote
0answers
69 views

Changing the date format of auth.log

I was looking to change the date format in which auth.log logs information. I could not find a way to do it. Is there a method to do this? My system uses rsyslog.
4
votes
2answers
463 views

How do I find seconds since midnight?

Using the date program, how can I calculate the number of seconds since midnight?
1
vote
1answer
22 views

Unzip all non-existing or older files from archive

The behaviour I'd like with unzip is to extract all files, overwriting any that are older than those in the archive, not touching any that are the same age or newer, and to never prompt. The options ...
0
votes
1answer
66 views

Mount changes directory time to 1970

We are developing an embedded Linux system using BusyBox v1.19.4. The system is working fine except for a strange mount issue with time and date. When we create a directory it has the correct time ...
15
votes
1answer
640 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: ...
1
vote
2answers
2k views

Unable to use date command to change specific date format in Bash shell on OS X terminal

I am using the date -d command to change a specific date format to another. Below is the example used currDate=`Wed 12 Feb 2014` formattedDate=`date -d"${currDate}" +%Y%m%d` echo $formattedDate
6
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 ...
2
votes
1answer
156 views

mkdir with date function behaves differently in script

I am trying to create a directory with a timestamp. If I type at the prompt mkdir "$(date +%Y-%m-%d_%H%M%S)" I get a directory named with the date as I would like. If I put the same line in a bash ...
6
votes
2answers
640 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 ...