0

if i have a given date so how can i find in what date sun and sat comming ... ?
i store 0 for sat and 6 for sun in database.

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by diafol
0

Get the day from the current date:

$current = date('w');
$nextSat = ($current == 6) ? 7 : 6 - $current;
$nextSun = ($current == 6) ? 1 : $nextSat + 1;
//a routine for adding days, eg for Sat:
$dateSat = date_create(date('Y-m-d'));
date_add($dateSat, date_interval_create_from_date_string("$nextSat days"));
echo date_format($dateSat, 'Y-m-d');

Edited by diafol

0

thanx all for reply
i am little bit confuse here..
basically what i want to do it ... if user set a task let says on 2012-june-2 so i have a form that is already sumiteed and data has been store to mysql it has two fields sat , sun ...if user set this to mon...tue wed.. etc .. so i have to check from above date when mon... or what ever he set in submitted form...i want to store that final date by calculating to mysql fields...

so $final_day_sat_move store calulated next date to mysql but not working above...
$date_plus_dueoff =2012-june-2

$weekday = date('D', strtotime($date_plus_dueoff));

                            $nextTues = strtotime('next tuesday');
                            $tuesday=date("Y-m-d",$nextTues);

                            $daydiff = floor((strtotime($tuesday) - strtotime($date_plus_dueoff) ) / 86400 );
                            //echo $daydiff;
                            //exit;
                            $final_day_sat_move=date('Y-m-d H:i:s', strtotime($date_plus_dueoff. ' + '.$daydiff.' days'));

Edited by mangel.murti: breif explain

0

Do not use seconds for date calculations - they can fail spectacularly with leap years and daylight saving features.

Unfortunately, I do not undertand your requirements:

if user set a task let says on 2012-june-2 so i have a form that is already sumiteed and data has been store to mysql it has two fields sat , sun ...if user set this to mon...tue wed.. etc .. so i have to check from above date when mon... or what ever he set in submitted form...i want to store that final date by calculating to mysql fields...

This makes little sense to me.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.