dstafford Posted September 30, 2008 Share Posted September 30, 2008 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 More sharing options...
Ingolme Posted September 30, 2008 Share Posted September 30, 2008 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 More sharing options...
dstafford Posted September 30, 2008 Author Share Posted September 30, 2008 That's great thanks..... I appreciate the help. Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 30, 2008 Share Posted September 30, 2008 Slightly optimized... var d = new Date();var day = d.getDay();if(day != 0) { d.setDate(d.getDate() - day);} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.