renathy Posted March 27, 2009 Report Share Posted March 27, 2009 Man ir datums no MySQL db unix timestamp formātā. $date Man ir dota nedēļas diena (skaitlis no 1-7). $day_of_week Man ir jādabūn $nearest_date mainīgajā datums (bez laika), kurš ir tuvākais pēc $date un ir nedēļas dienā $day_of_week. Kā to labāk izdarīt? Quote Link to comment Share on other sites More sharing options...
Grey_Wolf Posted March 27, 2009 Report Share Posted March 27, 2009 (edited) ja glabatu datumu SQL formataa DATE tad tas buut pavisam vienkarshi --> paprastiitu lai atgriez datumu kas ir 1 nedelju atpakalj, unix formataa arii to var izdariit, bet SQL tomer labak patiik savs formats (ja vajag pectam Unix formataa, tad uzreiz SQl kverejijaa arii var pankonverteet)) edit: nu jaa datumu unixtimestam var parekjinat vienkarshi datums=datums-(60*60*24*7) ... Edited March 27, 2009 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
v3rb0 Posted March 27, 2009 Report Share Posted March 27, 2009 function nearest_date($date, $day_of_week) { $diff = $day_of_week - date('N',$date); if($diff <= 0) { $diff = 7+$diff; } return date('Y-m-d', strtotime($diff.' days',$date)); } ja pareizi sapratu kas tiek prasīts. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.