Sponsored Content
Full Discussion: Date validity check
Top Forums Shell Programming and Scripting Date validity check Post 302873417 by Klashxx on Tuesday 12th of November 2013 05:25:46 AM
Old 11-12-2013
Python makes this task insanely simple:
Code:
>>> import time
>>> mask = '%Y-%m-%d'
>>> if time.strptime('2013-12-12', mask):                                                       
...    print "date ok"                                                                          ... 
date ok

Complete script:
Code:
#!/usr/bin/python
import time 
def check_mask ( datec,mask='%Y-%m-%d' ):
    try: 
        time.strptime(datec, mask)
    except ValueError:
        return False
    return True

f = open('./test.txt','rb')
for d in f:
   if not check_mask(d.rstrip()):
      print "Invalid: %s" % d,
f.close()


Last edited by Klashxx; 11-12-2013 at 07:00 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Validity

Hey, I was wondering how I could write a bash script which accepts: cat <<% | bash ./results06 ---------------------------------------------------------- Exam Results 2006 ---------------------------------------------------------- ... (1 Reply)
Discussion started by: Xerobeat
1 Replies

2. Shell Programming and Scripting

checking for command output validity

hi, i'm trying to write a script to check if the home directories of users are set correctly. below is an extract of the script here, i am trying to put the name of the owner of the home directory into the variable dirperm (by reading lines in /etc/passwd). however, it seems that when the... (1 Reply)
Discussion started by: roddo90
1 Replies

3. Shell Programming and Scripting

How to check date variable according to the current date?

Hi folks, I need to write a script that should activate a process according to the current hour. The process should be activatet only if the hour is between midnight (00:00) and 07:00. How should I create the condition? Thanks in advance, Nir (2 Replies)
Discussion started by: nir_s
2 Replies

4. Shell Programming and Scripting

Check for date

How to validate the first line from 1-8 position of audit file that contains the script run date... script could run in random dates. head -1 file1 20090516 100034837SHDHSHE (9 Replies)
Discussion started by: ford2020
9 Replies

5. Shell Programming and Scripting

Script to check the validity of password

Hi, I have to validate the passwords for 100s of unix users across several servers. I have the list of unix users and servers with passwrods. How can I check whether a password is correct or not using a single shell script? Note : I do not have root privileges on any server. All the... (1 Reply)
Discussion started by: Pupil
1 Replies

6. Shell Programming and Scripting

finding date numeral from file and check the validity of date format

hi there I have file names in different format as below triss_20111117_fxcb.csv triss_fxcb_20111117.csv xpnl_hypo_reu_miplvdone_11172011.csv xpnl_hypo_reu_miplvdone_11-17-2011.csv xpnl_hypo_reu_miplvdone_20111117.csv xpnl_hypo_reu_miplvdone_20111117xfb.csv... (10 Replies)
Discussion started by: manas_ranjan
10 Replies

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. Shell Programming and Scripting

Perl code to check date and check files in particular dir

Hi Experts, I am checking how to get day in Perl. If it is “Monday” I need to process…below is the pseudo code. Can you please prove the code for below condition. if (today=="Monday" ) { while (current_time LESS THAN 9:01 AM) ... (1 Reply)
Discussion started by: ajaypatil_am
1 Replies

9. Shell Programming and Scripting

Check, if date is not today

hello, in a file exist entries in date format YYYYMMDD. i want to find out, if there are dates, which isn't today's date. file: date example text 20140714 <= not today's date 20140715 <= not today's date 20140716 <= today's date my idea is to use Perderabo's datecalc ... (2 Replies)
Discussion started by: bora99
2 Replies

10. Shell Programming and Scripting

Confirming validity of programming language tools

so i have scripts that get run in ways similar to this: cat script.pl | perl - $1 $2 $3 cat script.rb | ruby - $1 $ 2 $3 my question is, how can i verify that that the "perl" or "ruby" or "python" tool being run on the box is actually a legit tool? meaning, someone may move the tool from... (2 Replies)
Discussion started by: SkySmart
2 Replies
DATETIMEIMMUTABLE.FORMAT(3)						 1					       DATETIMEIMMUTABLE.FORMAT(3)

DateTime::format - Returns date formatted according to given format

       Object oriented style

SYNOPSIS
public string DateTime::format (string $format) DESCRIPTION
string DateTimeImmutable::format (string $format) string DateTimeInterface::format (string $format) Procedural style string date_format (DateTimeInterface $object, string $format) Returns date formatted according to given format. PARAMETERS
o $object -Procedural style only: A DateTime object returned by date_create(3) o $format - Format accepted by date(3). RETURN VALUES
Returns the formatted date string on success or FALSE on failure. EXAMPLES
Example #1 DateTimeImmutable.format(3) example Object oriented style <?php $date = new DateTime('2000-01-01'); echo $date->format('Y-m-d H:i:s'); ?> Procedural style <?php $date = date_create('2000-01-01'); echo date_format($date, 'Y-m-d H:i:s'); ?> The above example will output: 2000-01-01 00:00:00 NOTES
This method does not use locales. All output is in English. SEE ALSO
date(3). PHP Documentation Group DATETIMEIMMUTABLE.FORMAT(3)
All times are GMT -4. The time now is 05:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy