Hi Monks,
I want to check if two given dates have a difference of maximum 6 months. I go about like this:
use Date::Calc qw(:all);
use strict;
my @data_date_confirm=();
my @data_date_birth=();
my $diab_confirm = '29/08/2013';
my $date_birth = '21/02/2013';
if($diab_confirm=~/(\d+)\/(\d+)\/(\d+)/)
{
my $day_confirm = $1;
my $month_confirm = $2;
my $year_confirm = $3;
@data_date_confirm = ($year_confirm, $month_confirm, $day_conf
+irm);
}
if($date_birth=~/(\d+)\/(\d+)\/(\d+)/)
{
my $day_birth = $1;
my $month_birth = $2;
my $year_birth = $3;
@data_date_birth = ($year_birth, $month_birth, $day_birth);
}
my $dd = Delta_Days(@data_date_birth, @data_date_confirm);
my $months_until_confirm = sprintf("%.1f", $dd/30);
if($months_until_confirm<=6)
{
print "They are different by more than 6 months!\n";
}
I realise though that this is not entirely correct, since I divide by 30 days. Is it a way to be more precise?
Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.