Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. date difference script

date difference script

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
perldata-structurestoolshelp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Tee
    wrote on last edited by
    #1

    Hi, I am trying to create a perl date difference script. I would like to put the date2 from a file and put it into an array. Then find the difference between that day and today. Here is what i got (it dont work). Please help. #!/usr/bin/perl # date calculator use Date::Calc qw(Delta_Days check_date); open (DATEFILE, "date.txt")|| die "couldn't open the file!"; @date2 = ; close DATAFILE; open (TODAYFILE, "today.txt") || die "couldn't open the file"; @today = ; print @today; print "\n" ; print @date2; print "\n"; $difference = Delta_Days(@today, @date2); print "There are $difference days before password expires\n"; close TODAYFILE;

    R S 2 Replies Last reply
    0
    • J Jay Tee

      Hi, I am trying to create a perl date difference script. I would like to put the date2 from a file and put it into an array. Then find the difference between that day and today. Here is what i got (it dont work). Please help. #!/usr/bin/perl # date calculator use Date::Calc qw(Delta_Days check_date); open (DATEFILE, "date.txt")|| die "couldn't open the file!"; @date2 = ; close DATAFILE; open (TODAYFILE, "today.txt") || die "couldn't open the file"; @today = ; print @today; print "\n" ; print @date2; print "\n"; $difference = Delta_Days(@today, @date2); print "There are $difference days before password expires\n"; close TODAYFILE;

      R Offline
      R Offline
      Rob
      wrote on last edited by
      #2

      Do you have to read in today's date from a file? iirc if you do

      $date = Date::EzDate->new();

      it would be able to give you today's date

      1 Reply Last reply
      0
      • J Jay Tee

        Hi, I am trying to create a perl date difference script. I would like to put the date2 from a file and put it into an array. Then find the difference between that day and today. Here is what i got (it dont work). Please help. #!/usr/bin/perl # date calculator use Date::Calc qw(Delta_Days check_date); open (DATEFILE, "date.txt")|| die "couldn't open the file!"; @date2 = ; close DATAFILE; open (TODAYFILE, "today.txt") || die "couldn't open the file"; @today = ; print @today; print "\n" ; print @date2; print "\n"; $difference = Delta_Days(@today, @date2); print "There are $difference days before password expires\n"; close TODAYFILE;

        S Offline
        S Offline
        Sethsdad
        wrote on last edited by
        #3

        This should work #!/usr/bin/perl # date calculator use Date::Calc qw(Delta_Days check_date); open (DATEFILE, "date.txt")|| die "couldn't open the file!"; @date2=<DATEFILE>; close DATEFILE; open (TODAYFILE, "today.txt") || die "couldn't open the file"; @today; @today=<TODAYFILE>; print @today; print "\n"; print @date2; print "\n"; $difference = Delta_Days(@today, @date2); print "There are $difference days before password expires\n"; close TODAYFILE; date.txt 2010 01 20 today.txt 2010 01 15

        J 1 Reply Last reply
        0
        • S Sethsdad

          This should work #!/usr/bin/perl # date calculator use Date::Calc qw(Delta_Days check_date); open (DATEFILE, "date.txt")|| die "couldn't open the file!"; @date2=<DATEFILE>; close DATEFILE; open (TODAYFILE, "today.txt") || die "couldn't open the file"; @today; @today=<TODAYFILE>; print @today; print "\n"; print @date2; print "\n"; $difference = Delta_Days(@today, @date2); print "There are $difference days before password expires\n"; close TODAYFILE; date.txt 2010 01 20 today.txt 2010 01 15

          J Offline
          J Offline
          Justin
          wrote on last edited by
          #4

          Thanks that works great. Here is what i came up with. #!/usr/bin/perl use Date::Calc qw(Delta_Days); use Time::Piece; ($sec, $min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); open (MYDATA, "data.txt") or die ("Error: cannot open file 'ARGV[0]'\n"); my @lines1 = <MYDATA>; # chomp @lines1; my $t = Time::Piece->strptime("@lines1", "%b %d,%Y"); $year1 = $year + 1900; $mon1 = $mon + 1; $mday1 = $mday; $year2 = ( $t->strftime("%Y")); $mon2 = ( $t->strftime("%m")); $mday2 = ( $t->strftime("%d")); $difference = Delta_Days($year1, $mon1, $mday , $year2, $mon2, $mday2); print "There were $difference days between Nat and Bree\n"; print "email user\n" if $difference <= 15; data.txt Jan 24, 2010

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups