473,388 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How can I loop through each date in a given time period

How can I loop through each date in a given time period so that I can add those dates as a column name in a table.
I want to create datatable with the person's name and hours he worked in a given time period. The user will select the dates and I want to show each day/date in that table as a column name. I have no idea how to do it. Please help.
Sep 2 '10 #1

✓ answered by Aimee Bailey

Usually you'd just iterate using the Days value of a TimeSpan, easy peasy :)

Expand|Select|Wrap|Line Numbers
  1. Public Function LoopThroughDates(ByVal dFrom As DateTime, ByVal dTo As DateTime) _
  2.                                         As List(Of DateTime)
  3.         Dim r As New List(Of DateTime)
  4.  
  5.         Dim diff As TimeSpan = dTo - dFrom
  6.  
  7.         For d = 0 To diff.Days
  8.             r.Add(dFrom.Date.AddDays(d))
  9.         Next
  10.  
  11.         Return r
  12.     End Function
  13.  

1 7373
Aimee Bailey
197 Expert 100+
Usually you'd just iterate using the Days value of a TimeSpan, easy peasy :)

Expand|Select|Wrap|Line Numbers
  1. Public Function LoopThroughDates(ByVal dFrom As DateTime, ByVal dTo As DateTime) _
  2.                                         As List(Of DateTime)
  3.         Dim r As New List(Of DateTime)
  4.  
  5.         Dim diff As TimeSpan = dTo - dFrom
  6.  
  7.         For d = 0 To diff.Days
  8.             r.Add(dFrom.Date.AddDays(d))
  9.         Next
  10.  
  11.         Return r
  12.     End Function
  13.  
Sep 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: CrystalDBA | last post by:
I am using SQL Server 2000. I need to query my database for all the contracts that came in during a certain time frame (user is prompted for reportingperiodid). Table - Periods Fields -...
3
by: Dave | last post by:
Hi I am hoping someone might be able to help me out with this. I am writing a helpdesk system which records agents logging in and out of the system. I need to write a stored procedure which...
1
by: Lei Guangfu | last post by:
Hi, I have a program need to check the value of a application available, and then decide whether to execute codes followed. In order to achieve this purpose, I use DO WHILE loop to judge the...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
1
by: sesling | last post by:
I need some help with a date/time field. We run several processing jobs each day. The start and end times are stored in separate columns. The data is stored as date and time. I want to run a...
1
by: wetsprockets | last post by:
Hello, I have two tables, WindVector (wind data) and DOH_FC88to07 (water quality samples). The WindVector table has the following fields: Date (short date) Time (short time) WindSpeed...
6
by: Jeremy Sanders | last post by:
Hi - I need to add support to a program for dates and times. The built-in Python library seems to be okay for many purposes, but what I would like would be Unix epoch style times (seconds relative...
1
by: dianatokatlidis | last post by:
Hello. I have 2 separate date fields in a query. One is called Effective_Date and the other is called Expiry_Date. I want to compare the time period between these 2 fields and select any records...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.