perl - Find the first day of the month a given date is in -
in perl, given variable $period_end_date being set to, say, '4/30/2014', how can set $period_start_date '4/1/2014' , $next_period_start_date '5/1/2014'? (i.e. set first of month , first of next month respectively.
i've tried using datetime module system not find it. thinking use substr extract pieces month , day can have 1 or 2 digits.
how change what's in between /'s 1?
if know input data in format mm/dd/yyyy
, , you're worried fact mm
, dd
can have either 1 or 2 digits, can use regex matching:
$period_end_date =~ m{(\d+)/(\d+)/(\d+)}; $month = $1; $day = $2; $year = $3;
i used m{}
format pattern matching rather //
in order avoid having escape /
characters within date. write pattern /(\d+)\/(\d+)\/(\d+)/
instead.
Comments
Post a Comment