Jump to content

Defaulting Date to a specific weekday


dstafford

Recommended Posts

OK... lots of date examples and guides however I have not been able to find some guidance getting a calendar/date field to default to the most recent Sunday date. This is a calendar script I have in a web page. So if it is Tuesday I would like the default date to reflect the previous Sunday. The basic code n the web page is the following.....Week Ending Date (Sunday Only): <script>DateInput('txtWeekEnd',true, 'MM-DD-YYYY')</script>This calls 'calendarDateInput.js' is a script that processes a drop down calendar that dates can be selected off.... Anyone have any thoughts???Appreciate your input..... Thanks

Link to comment
Share on other sites

You could check out the mysterious strtotime() function.

<?php echo(strtotime("last Sunday")); ?>

Edit:Oh, sorry, that's PHP.What you'd have to do in Javascript is to keep subtracting 1 to the day until the specified day is Sunday.Something like this:

var d = new Date();while(d.getDay() != 0) {  d.setDate(d.getDate() - 1);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...