Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Set defualt date as Week Day before Today.

Reply
Thread Tools

Set defualt date as Week Day before Today.

 
 
Phillip Vong
Guest
Posts: n/a
 
      12-11-2006
VB.Net and a simple aspx.net page.

I have this simple code that puts Today's date in these 2 textboxes. Can
some one tell me how to set these two boxes with yesterday's date excluding
weekends?

Thanks!
phil

--------------------------------



Dim dtmToday As String

dtmToday = Now.Date.ToString("MM/d/yyy")

TextBox1.Text = dtmToday

TextBox2.Text = dtmToday


 
Reply With Quote
 
 
 
 
Phillip Vong
Guest
Posts: n/a
 
      12-11-2006
Thanks, but that didn't work. Your code just took the date back 7 days
INCLUDING WEEKENDS. If the textbox is 12/11/06, it is now 12/4/06. If I
change the code to -1, it will go back one day but it does not disregard the
weekends. How do you disregard the weekends?



"Saubz" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Phillip,
>
> Try this out
>
>
> TextBox1.Text = DateAdd(DateInterval.Day, -7, DateTime.Now)
>
>
>
> "Phillip Vong" wrote:
>
>> VB.Net and a simple aspx.net page.
>>
>> I have this simple code that puts Today's date in these 2 textboxes. Can
>> some one tell me how to set these two boxes with yesterday's date
>> excluding
>> weekends?
>>
>> Thanks!
>> phil
>>
>> --------------------------------
>>
>>
>>
>> Dim dtmToday As String
>>
>> dtmToday = Now.Date.ToString("MM/d/yyy")
>>
>> TextBox1.Text = dtmToday
>>
>> TextBox2.Text = dtmToday
>>
>>
>>



 
Reply With Quote
 
 
 
 
Rad [Visual C# MVP]
Guest
Posts: n/a
 
      12-12-2006
On Mon, 11 Dec 2006 18:18:00 -0500, Phillip Vong wrote:

> Thanks, but that didn't work. Your code just took the date back 7 days
> INCLUDING WEEKENDS. If the textbox is 12/11/06, it is now 12/4/06. If I
> change the code to -1, it will go back one day but it does not disregard the
> weekends. How do you disregard the weekends?



Hey Philip,

Try this out. Its not pretty but it works

sub Main
' This should return monday the 11th
Console.WriteLine( _
GetLastBusinessDay(new DateTime(2006,12,12),1))
'This should return friday the 8th
Console.WriteLine( _
GetLastBusinessDay(new DateTime(2006,12,12),2))
Console.ReadLine()
end sub

function GetLastBusinessDay (theDate as DateTime, daysAgo as Integer) as
DateTime
'
' Some local variables
'
dim counter as integer
dim temp as DateTime =theDate
'
' Put in a loop
'
while true
'
' Do some error checking
'
if theDate=DateTime.MinValue
return DateTime.MinValue
end if

'
' Decrement the day
'
temp= temp.AddDays(-1)
'
' Check if it is a weekday
'
select case temp.DayOfWeek
case DayOfWeek.Monday to DayOfWeek.Friday
'
' It is! Increment the counter
'
counter=counter+1
end select
'
' Now check if the counter is equal to
' the days we want
'
if counter=daysago then
return temp
end if

end while
end function
--
Bits.Bytes
http://bytes.thinkersroom.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outlook ASP .Net Web Controls 3 12-22-2003 10:42 PM
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outlook ASP .Net 3 12-22-2003 10:42 PM
ASP.NET: Day / Work Week / Week / Month web calendar control with view like MS Outlook ASP .Net Building Controls 3 12-22-2003 10:42 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
defualt date in JS Kevin Song Javascript 3 07-23-2003 02:11 PM



Advertisments