Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Compare Date to today's date in shell script Post 303043888 by Neo on Monday 10th of February 2020 11:11:52 AM
Old 02-10-2020
You should not need awk (or any command line text processor) to convert from various date formats to unixtime (epoch time) and back again.

I spent a few hours today on MQTT with various date and time formats, passing between PHP and Node.js (Javascript) and back, converting unixtime to various formatted date strings and back.

I did not require any text processing software to do this.

Working with dates and time is very standard these days, and we generally do not need text processors to format date and time strings, convert between various formats, and back. This is all "standard stuff" in computer science for quite some time.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

compare today's date with date in a file

Hi I am very new to scripting, Can someone show me how to (in unix shell script) compare the system's date with a date in a file. The requirement is to somehow open this file (which will only have a date in it) and compare it with today's date. If they are equal execute a procedure below but if... (4 Replies)
Discussion started by: siog
4 Replies

2. Shell Programming and Scripting

Past date display ( today - N) in shell

Hi, Any idea to get display of date - n ( n=1,2,3,4 etc) ? For example , dtoudt will easily execute by dtoudt -3 and result is >dtoudt -3 1234852529 Date 2009-2-17 time 14:35:29 day 47 How to get it display in 20090217 instead ? Maybe you have other suggestion to display date... (0 Replies)
Discussion started by: rauphelhunter
0 Replies

3. Shell Programming and Scripting

Calculate 30/31 days from today date script

Hi Guys, I was working some time ago n was in need to calculate date 30/31 days from today including Feb (Leap yr stuff). Today date is variable depending on day of execution of script. I tried searching but was not able to get exactly what I needed....So at that I time I implemented by my own... (3 Replies)
Discussion started by: coolgoose85
3 Replies

4. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

5. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

6. Shell Programming and Scripting

Shell Scripting: Copy Files with Today's date

I was wondering the best way about finding files that were created today and copy them to a directory (grep ?). There can be multiple files for todays date or none. I am looking to copy all of the .lis files for todays date. I may need to modify the filename to include todays date but for the... (4 Replies)
Discussion started by: smkremer
4 Replies

7. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

8. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

9. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

10. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies
Time(3pm)						  LogReport's Lire Documentation						 Time(3pm)

NAME
Lire::Time - parses and prints date in formats common to many log files. SYNOPSIS
use Lire::Time qw/ syslog2cal /; my @ltime = localtime; while ( <LOGFILE> ) { #... my $time = syslog2cal( $m, $d, $t, @ltime ); } DESCRIPTION
This module supplies many functions to parse dates in formats that you are likely to encounter in log files. It also offers many functions to format epoch time in useful format. NOTE ABOUT FUNCTION EXPORT Altough all documented functions are exported by default to the caller namespace, you should explicitely import the functions you require since exporting by default isn't recommanded by the perl modules guidelines. DATE PARSING FUNCTIONS
This module includes several functions that convert between a more human readable date format and UNIX epoch time. All parsing functions will return the number of seconds since Jan 1 1970 00:00:00 UTC and will die() when passed invalid arguments. date2cal() my $time = date2cal( $year, $month, $day, $time, [$timezone] ); my $time = date2cal( "2001 Mar 20 09:32:29 +0100" ); This function will convert a date in the date(1) default output format to UNIX epoch time. The function accepts either the date in a string or splitted on whitespace. If the timezone component is omitted, the local timezone is assumed (usually based on the value of the TZ environment variable). syslog2cal() my $time = syslog2cal( $month, $day, $time, $local_tm_ref ); my $time = syslog2cal( "Mar 11 13:21:00", $local_tm_ref ); This function will convert a date in the syslog default output format to UNIX epoch time. The function accepts either the date in a string or splitted on whitespace. Since the syslog format doesn't contain timezone information, the local timezone is assumed (usually determined by the TZ environment variable). The last argument is a reference to an array returned by localtime(). my $local_tm_ref = [localtime()]; It is used to determine the year. clf2cal() my $time = clf2cal( "[18/Mar/2001:15:59:30 +0100]" ); This function will convert a date as found in Common Log Format to UNIX epoch time. DATE FORMATING FUNCTIONS
This module includes some functions to convert date in UNIX epoch time to some more human readable output. All functions will die() when passed invalid arguments. cal2rfc() print cal2rfc( $time ); This function will convert a date in UNIX epoch time to the RFC822 format (used in email, for example). A RFC822 date looks like Wed, 30 May 2001 12:45:13 +0000 The timezone offset specification will correspond to the local timezone (usually determined by the TZ environment variable). cal2ymdhms() print cal2ymdhms( $time ); This function converts a date in UNIX epoch time to a string of the form: YYYYMMDDHHMMSS This representation will correspond the time in the local timezone (usually determined by the TZ environment variable.) getMonthName() print getMonthName( 0 ); # Gives 'Jan' This function takes as parameter a number (0-11) representing the month (as returned by localtime() for example) and will return the English abbreviated name of that month ( Jan, Feb, etc. ). AUTHOR
Joost van Baal <joostvb@logreport.org> VERSION
$Id: Time.pm,v 1.10 2006/07/23 13:16:30 vanbaal Exp $ COPYRIGHT
Copyright (C) 2000-2002 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2006-07-23 Time(3pm)
All times are GMT -4. The time now is 03:33 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy