compare two dates in script

Posted on 1998-06-29
Last Modified: 2012-05-05
I need to write a script that will notify users of their password expiration after logging in to to
a Win95 client. The text file with the user's password expiration date will reside in their
$HOME directory. The script will reside in the Windows startup folder. The script should
compare the date in the file with the system date, and print a "Password will expire in x days"
message if the date in the file is less than 5 days than the current (system) date.
The script will also need to update the file in the user's $HOME directory with the new
password expiration date after the user changes his or her password.
Can I accomplish this with perl?  I would appreciate some source code to help me write
this solution. I installed Perl for Win95 and I want to start using its functionality, but I think I
need some help to get off the ground. I am digesting all the documentation now, but I have to
write this solution now!

Thanks in advance for your help!
Question by:denmarkw
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 84

Expert Comment

ID: 1208241
What's the format of the date in the text file?

Accepted Solution

tpryor earned 200 total points
ID: 1208242
answer to follow...

Expert Comment

ID: 1208243
OK , there are a couple parts to your question lets take them one at a time.

1) Read the file line by line looking for a match...

open(FILE, "pwd/file/path") || print couldnt open the file, $!;
while (<FILE>) {
      if ($_ =~ /$user/) { # be as specific as neeeded
            #### check dates todays vs pwd

2) Logic to check dates...

# I recomend storing the date as yymmdd
# makes for easy comparison
# use the library to help you format the dates
# i will give you the url for it

($user, $pwd, $user_date) = split(/\/, $_);
# this will split the matched record into fields

$today_julian_day = &today();
# this will give me the julian date for today

$days_ago = 30;
# freshness date

($month,$day,$year,$weekday) = &jdate($julian_day - $days_ago)
# this will format it into something a human can understand

$bench_mark_date = sprintf("%02d%02d%02d", $year, $month, $day);
# this will make it easy to compare

if($user_date <= $bench_mark_date){

#### Tell user to change pwd
#### close file
#### exit program


#### continue with program

3) if the user must change pwd

### present login screen with new pwd option

same as no.1, open pwd file read line by line when you find him split up the line change the password field write back to file.
make sure you look the file when writing to it.

I didnt go into to many details about reading the file and writeing because that is pretty basic. you can go to
and get a ton of info about that kind of stuff. The text file is simple just a file where each line is a record with each ellement in the record seperated by something ie
Im not sure of your programming level so Ill leave it at that, i dont wont to bore you with the basics if you already know them.

The tricky part is dealing with dates, as long as your system deals with julian dates (most do) this code will do the trick.
I will give you the url to to use it make sure you type
in your cgi before you call the time/date functions. And that you save the library in the same dir as your cgi.
 should be all set.

the url is...


Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1208244
># I recomend storing the date as yymmdd
># makes for easy comparison

And people are still amazed that software produced within the past few years, let alone today, has a Y2K problem... (Although in this case it won't fail catastrophically, it's so easy to do it right that you should use a 4 digit year).

I am not criticizing you, tpryor, just pointing out how embedded 2 digit years are in most people's thinking, leading to a $trillion problem.

Expert Comment

ID: 1208245

BTW the code example actually produces a 4 digit year.


Author Comment

ID: 1208246
Thanks for your comments!
Please lets clarify some of the code. I am just a beginner when it comes to Perl!
So I would appreciate any details for clarity.
First, the compare file on the client PC only has
the password expiration date.  This file has to be created and populated with the
system date after the first reboot which will force the user to change his or her Solaris
password. How do I create this file and put the current Win95 system date in it? How can
I control the date format?
Second, is the split necessary if only a date is in the compare file?
Third, why do we subrtract 30 days? After the first system reboot the script should force
a password change and update the expiration date by adding 60 days to the current date
and update the compare file on the client.  Any subsequent reboot should only compare the difference between the current system date and the date in the compare file.
If the compare date is less than the system date by 5 days or less, a window should pop
up on the Win95 client notifying the user of the number of days until expiration and should give the user the option to change his or her password from the pop-up window.
How can I create a GUI with Perl for win32?
Fourth, I need to call the Win95 "telnet" executable after the first reboot and whenever the
compare condition is met. How do I make system calls in Perl?
Thanks in advance for your assistance experts!

Knowledge is power, but it is only useful if it is shared!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question