Skip to content

Instantly share code, notes, and snippets.

@carld
Created November 22, 2016 20:28
Show Gist options
  • Save carld/c6861dbe1a126243a597de2a7744c247 to your computer and use it in GitHub Desktop.
Save carld/c6861dbe1a126243a597de2a7744c247 to your computer and use it in GitHub Desktop.
example use of awk to format a date
function convert_time(t) {
split(t,a,"/");
if (a[3] > 50) {
a[3] = sprintf("19%02d", a[3]);
} else {
a[3] = sprintf("20%02d", a[3]);
}
month = a[1];
day = a[2];
year = a[3];
x = sprintf("%d %d %d 12 00 00", year, month, day);
y = mktime(x);
return strftime("%m/%d/%Y", y);
}
{
print "11/30/00", "->", convert_time("11/30/00");
print "11/30/99", "->", convert_time("11/30/99");
print "11/30/89", "->", convert_time("11/30/89");
print "11/30/01", "->", convert_time("11/30/01");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment