Widespread Augmented Reality

Widespread Augmented Reality
Click on the image to get the Android Augmented Reality Heads up Display

Sunday, November 5, 2017

Android to PHP Calendar Week View

I need to display a week of data between the Sunday and Saturday that surround a given date.

Android:

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
//current date on mobile
String formattedDate = df.format(Calendar.getInstance().getTime());
//format the get
String url = HOME_PAGE+"/mobile/getsessions.php?sessDate="+formattedDate";

//
PHP:

$sessDate=mysqli_real_escape_string($dbconn, $sessDate);
//

//Get the day number out of 7 days
$weekdaynum = date('w', strtotime($sessDate));
// the following will handle what happens when a date falls on Sunday or Saturday.
// I DO NOT want to slide a week out in either direction
switch ($weekdaynum) {
case 0: // sunday
$startAtSun = strtotime('this sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));
break;
case 6: // saturday
$startAtSun = strtotime('last sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));
break;
default: // all other days
$startAtSun = strtotime('last sunday', strtotime($sessDate));
$endAtSat = strtotime('this saturday', strtotime($sessDate));
break;
}

$format = 'Y-m-d';
$week_start = date($format, $startAtSun);
$week_end = date($format, $endAtSat);

1 comment: