Skip to content

Instantly share code, notes, and snippets.

@kylejohnson
Last active December 20, 2015 02:09
Show Gist options
  • Select an option

  • Save kylejohnson/6054390 to your computer and use it in GitHub Desktop.

Select an option

Save kylejohnson/6054390 to your computer and use it in GitHub Desktop.
Show days and hour since now
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $var = 'autosnap-hourly-2013-03-27_0900';
my @split = split('-', $var);
my $year = $split[2];
my $month = $split[3];
my $day = substr($split[4], -7, 2);
my $hour = substr($split[4], -4, 2);
my $minute = substr($split[4], -2, 2);
my $time = timelocal(0, $minute, $hour, $day, $month, $year);
my $diff_days = int(($time - time()) / 86400);
my $diff_hours = int((($time - time()) % 86400) / 3600);
print "$diff_days days and $diff_hours hours\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment