Functions
WebDev/*nix assorted functions & hacks
Search
find all
Array
-
Bash
-
Classes
-
Config
-
DateTime
-
Debug
-
dotjs
-
File
-
foooo
-
Git
-
HTML
-
Images
-
Javascript
-
Linux
-
Math
-
Misc
-
MySQL
-
OS X
-
Reading
-
Redis
-
Shell scripts
-
snippets
-
SQL
-
Strings
-
TextMate
-
Web
-
\(^o^)/ Fun!
-
_Misc hacks
-
_Pages
SQL
* Readme
Date range example
rename database with triggers
3
found
auth
Name:
Category: SQL
Body:
// I needed this in two other functions, so pulled it out. // It always takes me an hour to remember which goes where, and this works and is simple. Sort of. function get_period_sql($period) { $today = date('Y-m-d'); // weird as its behavior and input order is, mktime() is useful $week = date('Y-m-d', mktime(1, 1, 1, date('m'), date('d')+7)); $month = date('Y-m-d', mktime(1, 1, 1, date('m')+1, date('d'))); switch ($period) { case 'vandaag': $date_sql = " AND ((a.date BETWEEN '$today 00:00:00' AND '$today 23:59:59') OR (a.use_end_date = 1 AND a.date < '$today 23:59:59' AND end_date > '$today 00:00:00'))"; break; case 'week': $date_sql = " AND ((a.date BETWEEN '$today 00:00:00' AND '$week 23:59:59') OR (a.use_end_date = 1 AND a.date < '$week 23:59:59' AND end_date > '$today 00:00:00'))"; break; case 'maand': $date_sql = " AND ((a.date BETWEEN '$today 00:00:00' AND '$month 23:59:59') OR (a.use_end_date = 1 AND a.date < '$month 23:59:59' AND end_date > '$today 00:00:00'))"; break; default: $date_sql = " AND (a.date > '$today 00:00:00' OR (a.use_end_date=1 AND a.end_date > '$today 00:00:00'))"; break; } return $date_sql; }
Footer