Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How to get the days names between two dates in vb.net.

Ex- Fromdate(7/16/2012)
Todate(7/22/2012)

OutPut
7/16/2012
7/17/2012
7/18/2012
7/19/2012
7/20/2012
7/21/2012
7/22/2012

Like that..
I need to assign those dates into textboxes...


Thanks in advance
Sucharitha
Posted
Updated 31-Jul-12 20:49pm
v4

Try this:

VB
Dim startDay As Date
        Dim endDay As Date
        startDay = New Date(2012, 7, 16)
        endDay = New Date(2012, 7, 22)
        Dim dayCtr As Date
        dayCtr = startDay
        Do While (dayCtr <= endDay)
            MessageBox.Show(dayCtr.Date.Day & "-" & dayCtr.Date.DayOfWeek.ToString())
            dayCtr = dayCtr.AddDays(1)
        Loop
 
Share this answer
 
Please can any body give me the code
No. It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


Read about: DayofWeek property exposed by DateTime structure.
Refer:
DateTime.DayOfWeek Property[^]
MSDN: DateTime Structure[^]
 
Share this answer
 
Please can any body give me the code
No. It does not work like this here.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.


Read about: DayOfWeek property exposed by DateTime structure.
Refer:
DateTime.DayOfWeek Property[^]
MSDN: DateTime Structure[^]
 
Share this answer
 
Comments
RagSuchi 1-Aug-12 2:49am    
Hi Sandeep,
Thanks for your advice.
n.podbielski 20-Nov-12 3:55am    
I was curious way this question has many answers. Yourself added 2 :)
But seriously, your advice is pointless since he got code in other answers :sigh:
Sandeep Mewara 20-Nov-12 4:56am    
It was a bug reported to CP about duplicate answers getting posted at times. This being one of those cases. Thanks for pointing. Removed.

UPDATE:
Well, unable to delete currently. "Unexpected error during delete attempt. Please try again later."

Will delete one of the duplicates later.
n.podbielski 20-Nov-12 5:16am    
No wories, just saying :)
gives the dates in loop

VB
Dim startDay As Date
Dim endDay As Date
startDay = TextBox12.Text
endDay = TextBox13.Text
Dim dayCtr As Date
dayCtr = startDay
Do While (dayCtr <= endDay)
    'MessageBox.Show(dayCtr.Date.Day & "-" & dayCtr.Date.DayOfWeek.ToString())
    MessageBox.Show(dayCtr.Date)
    dayCtr = dayCtr.AddDays(1)
Loop
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900