Skip to content

Instantly share code, notes, and snippets.

@scottwalters
Created November 11, 2011 04:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save scottwalters/1357197 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use DateTime;
my $d = DateTime->from_epoch( epoch => 1320985777 )->truncate(to => 'day');
for( 1 .. 10 ) {
$d->subtract( months => 1 )->truncate( to => 'day' );
print scalar localtime $d->epoch, "\n";
}
--------------------------------------------8<-----------------------------------
Mon Oct 10 20:00:00 2011
Sat Sep 10 20:00:00 2011
Wed Aug 10 20:00:00 2011
Sun Jul 10 20:00:00 2011
Fri Jun 10 20:00:00 2011
Tue May 10 20:00:00 2011
Sun Apr 10 20:00:00 2011
Thu Mar 10 19:00:00 2011
Thu Feb 10 19:00:00 2011
Mon Jan 10 19:00:00 2011
@scottwalters
Copy link
Author

use strict;
use warnings;
use DateTime;
my $d = DateTime->from_epoch( epoch => 1320985777 )->set_time_zone('GMT')->truncate(to => 'day');
for( 1 .. 10 ) {
$d->subtract( months => 1 );
print scalar localtime $d->epoch, "\n";
}

--------------------------------------------8<-----------------------------------

Mon Oct 10 20:00:00 2011
Sat Sep 10 20:00:00 2011
Wed Aug 10 20:00:00 2011
Sun Jul 10 20:00:00 2011
Fri Jun 10 20:00:00 2011
Tue May 10 20:00:00 2011
Sun Apr 10 20:00:00 2011
Thu Mar 10 19:00:00 2011
Thu Feb 10 19:00:00 2011
Mon Jan 10 19:00:00 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment