Christopher Chin
Christopher Chin

Reputation: 61

Getting a Day from Date in Perl

Is there a way to find out day of the week when provided a date. How would I code this in Perl?

For example

Given 02-02-2016(dd-mm-yyyy) outputs Friday Note: Without using any modules.

Upvotes: 0

Views: 174

Answers (1)

Schwern
Schwern

Reputation: 165606

Note: Without using any modules.

Calendaring is hard. No, calendaring is REALLY HARD! It's very easy to get wrong. Use a module.

Fortunately there's a built in module to do this, Time::Piece. It has strptime to parse the date into an object. From there you can ask it a great number of things.

use v5.10;
use strict;
use warnings;
use Time::Piece;

my $time = Time::Piece->strptime("02-02-2016", "%d-%m-%Y");
say $time->fullday;

Upvotes: 14

Related Questions