Date/Time function code

1. Senior Member
Join Date
Dec 1969
Posts
613

## Date/Time function code

Hello,<BR><BR>I am trying to code the following logic in vbscript/asp on sqlserver. <BR>The users have to turn in their timesheet every week by 12:00noon on Monday for the prior week. I am using the timesheet enddate and the system date to determine if it is in by 12noon. The timesheet week begins on Monday, ends on Sunday, then that week&#039s timesheet is turned in the day after, on Monday. <BR>My pseudocode is :<BR><BR>Get sysdate<BR>If sysdate &#060;=(timesheet enddate -6 days) /*because they can turn their timesheets in any time during that week prior to monday*/ then<BR> If it is past noon for this monday then<BR> response.redirect...<BR> end if<BR>End if<BR><BR>Does this logic sound correct, and does anyone know how I can get some of the pseudocode into real code?<BR><BR>Thanks<BR> <BR> <BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Date/Time function code

Not sure I understand all the logic of what you are doing. What harm if they turn it in after noon? What does that affect? And what do you do if you are processing this on Tuesday? <BR><BR>But never mind...changing your pseudo code into the real stuff is easy:<BR><BR>&#060;%<BR>If Date() &#060;= DateAdd("d", -6, RS("timesheetEnddate") ) Then<BR> &nbsp; If WeekDay(Date)=2 AND Hour(Now) &#062;= 12 Then<BR> &nbsp; &nbsp; &nbsp; response.redirect...<BR> &nbsp; end if<BR>End if<BR>%&#062;<BR><BR>But I really feel that is not *truly* the solution. Maybe if you explain all the "if" conditions more?<BR><BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
613

## RE: Date/Time function code

Actually for cost center and client billing reasons, it can&#039t be turned in after 12:00pm Monday. I&#039m sure there will be special circumstances that will not follow this rule, but those are handled by accounting dept, not by the app. <BR><BR>So, for example, <BR>Mon 16th-Sun 22nd is the week for the timesheet. That timesheet must be turned in by Mon 23rd at noon. Or it can be turned in anytime between Mon 16th 12:01pm, and Mon 23rd 12:00pm. (Since some people may only work the 16th, then leave for vacation the next day, they will turn it in on the 17th.)<BR>So far I have....<BR><BR>MonDate = sStartDate<BR>TueDate = dateadd("d",1,sStartDate)<BR>WedDate = dateadd("d",2,sStartDate)<BR>ThuDate = dateadd("d",3,sStartDate)<BR>FriDate = dateadd("d",4,sStartDate)<BR>SatDate = dateadd("d",5,sStartDate)<BR>SunDate = dateadd("d",6,sStartDate)<BR>&#039 the previous is the days of the timesheet week, so I will use the Sunday as a starting point 3 lines down<BR>CurrentDate = date()<BR>CurrentTime = time()<BR>endcutoffdate = dateadd("d",1,SunDate) &#039this is Monday, the cutoff date for that pay period<BR>begcutoffdate = dateadd("d",-6,endcutoffdate) &#039this is Tuesday, 6 days prior within the pay period<BR>if CurrentDate &#062;= begcutoffdate and &#060;= endcutoffdate then &#039it is within that week and acceptable for that week.<BR> if weekday(date)=2 and hour(now) &#062;= 12 then<BR> Response.Write("cutoff")<BR> end if<BR>end if<BR><BR>This seems correct, but I have not taken into account the users turning this in for Monday 16th from 12:01pm to 11:59pm.<BR><BR>Does this make sense?<BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## RE: Date/Time function code

What I am missing: Where does sStartDate come from?<BR><BR>Is it a field in the DB? In the form the user is submitting? If it is in the form the user is submitting, what do you do about a bogus value? (e.g., on Monday the 9th at 3:00PM, they submit a time sheet that has the 9th as the startdate...even though the time sheet is really from the prior week.)<BR><BR>So pardon a little paranoia:<BR><BR>&#060;%<BR>submitTime = Now<BR><BR>If sStartDate &#060;&#062; dateValue( sStartDate ) Then<BR> &nbsp; Response.Write "start date not given as just a date"<BR>End If<BR>If WeekDay( sStartDate ) &#060;&#062; vbMonday Then<BR> &nbsp; Response.Write "start date is not a Monday!"<BR>End If<BR><BR>&#039 Now get the "start time" for entering time card for this week:<BR>startTime = DateAdd( "h", 12, sStartDate ) &#039 should be noon, on Monday<BR><BR>If submitTime &#060; startTime Then<BR> &nbsp; Response.Write "You can&#039t submit a time card for this week until noon Monday"<BR>End If<BR><BR>If submitTime &#062;= DateAdd( "w", 1, startTime ) Then<BR> &nbsp; Response.Write "Sorry, you should have submitted that by noon Monday!"<BR>End If<BR><BR>%&#062;<BR><BR>Of course, all those THENs would presumably really lead off to Response.Redirects of something like that, but you get the idea.<BR><BR>

## Just a check of something in your solution

Hi don&#039t mean to be rude or offend or anything..<BR>I agree with what your saying but is the "w" in the following valid?<BR>"If submitTime &#062;= DateAdd( "w", 1, startTime ) Then<BR> Response.Write "Sorry, you should have submitted that by noon Monday!"<BR>End If"<BR>I thought that you could only use d for day, M for month, and y for year I think you may have to use this instead.<BR>If submitTime &#062;= DateAdd( "d", 7, startTime ) Then<BR> Response.Write "Sorry, you should have submitted that by noon Monday!"<BR>End If<BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
96,118