Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Weekday function

Status
Not open for further replies.

gradinumcp

IS-IT--Management
Apr 6, 2005
85
US
Hi! I have a piece of code where the user picks a date from the calendar. Depending on the date he has picked, it should display all the days of the week.

Example: If the user picked 18th October 2005 from the calendar, then it should display:

Sunday 10/16/2005
Monday 10/17/2005
Tuesday 10/18/2005
Wednesday 10/19/2005
Thursday 10/20/2005
Friday 10/21/2005
Saturday 10/22/2005



I know this can be displayed if the date picked is todays date by using <%=Date()-Weekday(Date())+1%> for Sunday and so on.

However how do i accomplish this when the Date is what the user has picked--so kind of change Date() to say <%=request("PullDate")%>--but what would be the correct code for that??

Here's my code:

<td>Week<input class=fields readonly name="PullDate" <% if request("PullDate")<>"" then %>value="<%=request("PullDate")%>"<% else %>value="<%=Date()%>"<% end if %>

Sunday=<%=Date()-Weekday(Date())+1%>
Monday=<%=Date()-Weekday(Date())+2%>
Tuesday=<%=Date()-Weekday(Date())+3%>
Wednesday=<%=Date()-Weekday(Date())+4%>
Thursday=<%=Date()-Weekday(Date())+5%>
Friday=<%=Date()-Weekday(Date())+6%>
Saturday=<%=Date()-Weekday(Date())+7%>

 

checkout functions isDate() and CDate()

A smile is worth a thousand kind words. So smile, it's easy! :)
 
You've already answered your own question. Replace Date() with request("PullDate"). However, because everything from the user is a string, you'll need to tell ASP that it's a date, by converting it to one via CDate(), which goes around your user's input, like CDate(request("PullDate")), which damber hinted at.

You must ensure that the user enters a valid date, though, or an error with be thrown. Hence damber's suggestion of IsDate().
 
Thanks for your suggestions guys--however I am still having the problem.

When I put Cdate(NewDate) where NewDate=<%=request("PullDate"), it returns a value like 12:00:00 AM, which is clearly not the date i requested. When I do IsDate(NewDate), it returns False.

Besides how do I accomplish getting the dates of the whole week by using this expression, <%=Date()-Weekday(Date())+1%> for Sunday and <%=Date()-Weekday(Date())+1%> for Monday and so on--just by replacing the Date() with say NewDate??
 
If IsDate(request("PullDate")) is false, that means that no valid date was submitted in the field "PullDate". When you try to convert it (probably empty) into a date using CDate, it converts nothing into the simplest, earliest possible date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top