I am using this shell program where i need to display date with time for some particular task. For some reason the date is not working and its only showing time.
date +'%H:%M:%S Calling' >> /home/hmm/AppFlatForRent/log.txt #calling
Can anyone tell me whats wrong with it
You're only adding formatting to the date command for the time in hours minutes and seconds (i.e. '%H:%M:%S'). Try:
date +'%Y-%b-%d %H:%M:%S Calling' >> /home/hmm/AppFlatForRent/log.txt #calling
Related
I am writing a BASH script that calls an API that presents metrics for specific time-frames. I plan to run the script on a cron job on the 1st of each month, the API call needs to contain the start and end time and be in a epoch format with milliseconds. Milliseconds should be ok to set to 000 as it doesnt need to be that specific but the API requires it.
How can I code the script to look at the current human readable time then look at the exact same time exactly 1 calendar month before, then convert both outputs to epoch, and then enter the epoch times in the curl command as a variable?
Example:
Script runs at 1am on July 1st, script then understands a full calendar month before was June 1st, converts both to epoch, places them into the curl command using variables.
I understand how to get a human readable date for 1 month ago, however I am unsure how best to convert these dates to epoch.
date --date="1 month ago" +"%d%m%Y"
To create a variable using date in epoch times with milliseconds:
ENDDATE=`date +%s%N | cut -b1-13`
STARTDATE=`date --date="1 month ago" +%s%N | cut -b1-13`
Use these variables in the cURL command.
I have the following formula
DATE(YEAR(E687);MONTH(E687);DAY(E687))
and I want to use the TIME function as well. E.g:
DATE(YEAR(E687);MONTH(E687);DAY(E687)) - Time(10;0;0)
The reason is that I have guys working on my Excel sheetfrom CAT and PST
I am getting a date from the server and if a PST user adds data I want to minus 10 hrs from the server date to ensure I get the correct data in CAT.
I know my date above only shows date and not time but I want to remove 10hrs so see if it was done the previous day or the same day.
As comments on post suggests make sure your excels separation symbol e.g ; or , - Check regional settings.
Worked!
I want to increment time in -rfc-3339 format and have used following command :
`date --date="(date --rfc-3339=seconds) + 5 minutes"`
but after increment current time by 5 minutes, it shows the incremented system time in standard format :
Thu Feb 2 20:06:30 IST 2017.
I want the desired output in --rfc-3339 format i.e
2017-02-02 20:06:30+05:30.
Thanks in advance.
This is pretty simple. The --rfc-3339 flag tells the date command how to format its output, but you're putting it inside the specifier for the input date — what date to format.
In your command
date --date="(date --rfc-3339=seconds) + 5 minutes"
the --date="stuff" part tells the command which date you want to show (as opposed to the default of "right now"). It looks like you might be doing some sort of math with "take the current date and add five minutes", but actually the part in () is not valid input and is ignored. You could say date --date="(colorless green ideas sleep furiously) + 5 minutes", and you'll get the same results — or just date --date="+5 minutes".
But of course, that's in the standard output format. To get it in RFC 3339 format, simply add that flag, outside of the input date string:
date --date="+5 minutes" --rfc-3339=seconds
and there you go.
I am working on the Jenkins jobs. There is already a job created with this command. I need someone's help to guide me about the time settings in command line. There are two variables for start and end time. Kindly , can you explain that what will be the start and ending time in simple English
export start_date=$(date -d "yesterday 00:00:00 " +%s)
export end_date=$(date +%s)
From man date:
%s is the number of seconds since 1970-01-01 00:00:00 UTC
So for the start_date, the command is saying grab the date from yesterday, with time 00:00:00. And then once you have that date, then get the number of seconds elapsed from the Unix epoch (01/01/1970) until that date. So for example, today is 4/14/2016, so start_date is equal to the number of seconds from 1/1/1970 00:00:00 to 4/13/2016 00:00:00.
The end_date is the number of seconds elapsed since the Unix epoch (01/01/1970), from right now (the current time).
I need to write a simple script of in bash. How do i get the current time in Linux in the specific format of
HH:MM am or pm, eg 05:30 a.m.
Use date formatter
$date + "%I:%M %P"