Set defualt date as Week Day before Today.

Discussion in 'ASP .Net' started by Phillip Vong, Dec 11, 2006.

  1. Phillip Vong

    Phillip Vong Guest

    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
     
    Phillip Vong, Dec 11, 2006
    #1
    1. Advertising

  2. Phillip Vong

    Phillip Vong Guest

    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" <> wrote in message
    news:...
    > 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
    >>
    >>
    >>
     
    Phillip Vong, Dec 11, 2006
    #2
    1. Advertising

  3. 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
     
    Rad [Visual C# MVP], Dec 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    3
    Views:
    1,871
    Alexandre
    Dec 22, 2003
  2. Andy
    Replies:
    1
    Views:
    743
  3. Guest
    Replies:
    3
    Views:
    538
    Alexandre
    Dec 22, 2003
  4. Guest
    Replies:
    3
    Views:
    1,150
    Alexandre
    Dec 22, 2003
  5. Kevin Song

    defualt date in JS

    Kevin Song, Jul 22, 2003, in forum: Javascript
    Replies:
    3
    Views:
    111
    Dr John Stockton
    Jul 23, 2003
Loading...

Share This Page