Skip to content

Instantly share code, notes, and snippets.

@robertjmoore
Created August 11, 2012 18:50
Show Gist options
  • Save robertjmoore/3326340 to your computer and use it in GitHub Desktop.
Save robertjmoore/3326340 to your computer and use it in GitHub Desktop.
Generate a string detailing all the cohorts a given user belongs to
<?php
function getQuarter() {
$monthNumber = intval(date("m"));
return floor(($monthNumber - 1) / 3) + 1;
}
function buildWeek() {
if (date('l') == "Sunday") {
$sundayTime = time();
}
else {
$sundayTime = strtotime('last sunday');
}
$WY = date("Y", $sundayTime);
$WM = date("m", $sundayTime);
$WD = date("d", $sundayTime);
return sprintf("WY:%s;WM:%s;WD:%s;", $WY, $WM, $WD);
}
function getTimeString() {
return sprintf("Y:%s;Q:%s;M:%s;%sD:%s;H:%s", date("Y"), getQuarter(), date("m"), buildWeek(), date("d"), date("H"));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment