note 94497 added to function.date

From: Date: Sun, 08 Nov 2009 19:47:33 +0000
Subject: note 94497 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-162649@lists.php.net to get a copy of this message
Function which simply returns numeric specification what day of week was(or will be) at given date (same schema as date("w")). Works both for future and past dates. Counting starts from 0 for Sunday and ends at 7 for Saturday. Hope it will help anybody. ;) Here's the function: function return_day_of_week($date){ $sy=substr($date, 0, 4); $sm=substr($date, 5, 2); $sd=substr($date, 8, 2); $date_utc=mktime(0,0,0,$sm, $sd, $sy); $today_utc=mktime(0,0,0,date("m"), date("d"), date("Y")); if($date_utc>$today_utc){ $future_date=1; $temp=$date_utc; $date_utc=$today_utc; $today_utc=$temp; } $utc_difference=$today_utc-$date_utc; $weeks_count=($utc_difference)/604800; if($weeks_count<10) $weeks_count=substr($weeks_count, 0, 1); else if($weeks_count<100) $weeks_count=substr($weeks_count, 0, 2); else if($weeks_count<1000) $weeks_count=substr($weeks_count, 0, 3); $days_rest_count=substr(($utc_difference-$weeks_count*604800)/86400, 0, 1); $was_day_of_week=date("w")-$days_rest_count; if($was_day_of_week < 0){ if($future_date==1) $was_day_of_week=0-$was_day_of_week; else $was_day_of_week+=7; } return $was_day_of_week; } ---- Server IP: 69.147.83.197 Probable Submitter: 94.254.135.169 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/94497 Del: integrated -- https://master.php.net/note/delete/94497/integrated Del: useless -- https://master.php.net/note/delete/94497/useless Del: bad code -- https://master.php.net/note/delete/94497/bad+code Del: spam -- https://master.php.net/note/delete/94497/spam Del: non-english -- https://master.php.net/note/delete/94497/non-english Del: in docs -- https://master.php.net/note/delete/94497/in+docs Del: other reasons-- https://master.php.net/note/delete/94497 Reject -- https://master.php.net/note/reject/94497 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162649) next »