Click here to Skip to main content
12,458,160 members (53,751 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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 31-Jul-12 19:55pm
Updated 31-Jul-12 20:49pm
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this:

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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[^]
  Permalink  
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 :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

gives the dates in loop

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
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100