Question Date Problem

arsalangodil

Member
Joined
Dec 14, 2009
Messages
6
Programming Experience
Beginner
Hi,

I want biweekly start date and biweekly end date.

For Example:

If i select date from datepicker 12/14/2009 and week start day is monday then start date should be 11/30/2009 And End Date should be 12/13/2009.

And if i select date from datepicker 12/15/2009 and week start day is monday then it should show start date 12/14/2009 not 12/1/2009 or 12/7/2009.

I m totally confused...please help..
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Dim StartWeekDay As String = "Mon"
Dim NumberOfDaysInWeek = 7
Dim StartDate As Date = Nothing
Dim EndDate As Date = Nothing
Dim MyDate As Date = DateSerial(2009, 12, 15)
Do While Format(MyDate, "ddd") <> StartWeekDay
MyDate = DateAdd(DateInterval.Day, -1, MyDate)
Loop
StartDate = MyDate
EndDate = DateAdd(DateInterval.Day, NumberOfDaysInWeek - 1, MyDate)
MsgBox(StartDate)
MsgBox(EndDate)
 

arsalangodil

Member
Joined
Dec 14, 2009
Messages
6
Programming Experience
Beginner
No this is not the solution of my question. i want biweekly dates not weekly dates
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Dim OneOfTheDayRequired = DateSerial(2009, 11, 30)
Dim StartWeekDay As String = "Mon"
Dim NumberOfDaysInWeek = 7
Dim StartDate As Date = Nothing
Dim EndDate As Date = Nothing
Dim MyDate As Date = DateSerial(2009, 12, 14)
Do While Format(MyDate, "ddd") <> StartWeekDay Or DateDiff(DateInterval.Day, OneOfTheDayRequired, MyDate) Mod 14 <> 0
MyDate = DateAdd(DateInterval.Day, -1, MyDate)
Loop
StartDate = MyDate
EndDate = DateAdd(DateInterval.Day, NumberOfDaysInWeek * 2 - 1, MyDate)
MsgBox(StartDate)
MsgBox(EndDate)
 

arsalangodil

Member
Joined
Dec 14, 2009
Messages
6
Programming Experience
Beginner
Hi send2te,

I am working on periods Daily, Weekly, BiWeekly, SemiMonthly, Monthly.

I have two more questions.

In SemiMonthly i have day periods defined like 1 to 16 and 2 to 17. I want to make start date like 1/1/2009 and end date like 1/16/2009 but if a month have 30 days then next period start date should be 1/17/2009 and 1/30/2009.

In Monthly i have initial day defined like i want to start month from 2nd then the month start date should be 1/2/2009 and end date should be 2/1/2009.

Thnks in advance..
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Dim StartDate As Date = Nothing
Dim EndDate As Date = Nothing
Dim MyDate As Date = DateSerial(2009, 12, 14)
If MyDate.Day < 17 Then
StartDate = DateSerial(MyDate.Year, MyDate.Month, 1)
EndDate = DateSerial(MyDate.Year, MyDate.Month, 16)
Else
StartDate = DateSerial(MyDate.Year, MyDate.Month, 17)
EndDate = DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, MyDate))
End If
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

There is one mistake in already provided code:

Use the following one instead:

Dim StartDate As Date = Nothing
Dim EndDate As Date = Nothing
Dim MyDate As Date = DateSerial(2009, 12, 14)
If MyDate.Day < 17 Then
StartDate = DateSerial(MyDate.Year, MyDate.Month, 1)
EndDate = DateSerial(MyDate.Year, MyDate.Month, 16)
Else
StartDate = DateSerial(MyDate.Year, MyDate.Month, 17)
EndDate = DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, DateSerial(MyDate.Year, MyDate.Month, 1)))
End If
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
EndDate = DateAdd(DateInterval.Day, -1, DateAdd(DateInterval.Month, 1, DateSerial(MyDate.Year, MyDate.Month, 1)))
You really need to start using the .NET functionality, send2te - it makes code much simpler and also easier to read:-

Code:
EndDate = New Date(Mydate.Year, Mydate.Month, 1).AddMonths(1).AddDays(-1)
or even easier still :-

Code:
EndDate = New Date(Mydate.Year, Mydate.Month, Date.DaysInMonth(Mydate.Year, Mydate.Month))
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
Nearly forgot the faster typing option :D

Code:
With Mydate
    EndDate = New Date(.Year, .Month, Date.DaysInMonth(.Year, .Month))
End With
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Dear IntertiaM

Thats great. Thanks for your comments. I realy need to start exploring new things ...

Off course easy syntax can make like easy ... and in future I will adopt the same as you mentioned.

In fact I am logical but lazy and explore some thing upto my requirements.

One somebody asked what to do to get rounded value upto 0 decimal place ...
At this time I know only int() function that was taking integer portion only.
v=3.4
int(v) = 3
v=3.7
and int(v)=3

So without exploring the actual function I told him to use

int(v+0.5) will give you always a rounded value upto 0 decimal places ...

Once a guy who was expert in algorithm asked to write a software that will accept always 4 charcter string and present all 16 different combinations ...


So If input was "Send" I need to produce remaining 15 strings like "endS", "Snde" etc.

It was not simple program and I need to explore proper algorithm for this ....

But I can not easily explore some new thing ... so what I have written

X="Send"
Dim A(4)
A(1)="S"
A(2)-"e"
A(3)="n"
A(4)="d"
for i=1000 to 9999
if i contains 1 and i contains 2 and i contains 3 and i contains 4 then


msgbox A(val(mid(i,1,1)) & A(val(mid(i,2,1)) & A(val(mid(i,3,1)) & & A(val(mid(i,4,1))



end if
next
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
I realy need to start exploring new things ...

At this time I know only int() function that was taking integer portion only.
v=3.4
int(v) = 3
v=3.7
and int(v)=3

int(v+0.5) will give you always a rounded value upto 0 decimal places ...
Yes, in old VB6 or below, that would have been fine. But programmers who are more intelligent than me ;) have thought about all the 'tricks' we used to have to write, and have now coded them for us :-

Code:
Math.Ceiling(3.4) = 4
Math.Ceiling(3.7) = 4
I think it's time you removed your Microsoft.VisualBasic reference. I know it will make writing code difficult for a while (I remember when I decided to go from VB6 to 2005 :eek: ), but you will write better code afterwards :D
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
Yes, in old VB6 or below, that would have been fine. But programmers who are more intelligent than me ;) have thought about all the 'tricks' we used to have to write, and have now coded them for us :-

Code:
Math.Ceiling(3.4) = 4
Math.Ceiling(3.7) = 4
I think it's time you removed your Microsoft.VisualBasic reference. I know it will make writing code difficult for a while (I remember when I decided to go from VB6 to 2005 :eek: ), but you will write better code afterwards :D

{Be hAppy}

Dear IntertiaM,

How can I remove the Microsoft.VisualBasic reference.

Usually I don't add using Imports ...
 

InertiaM

Well-known member
Joined
Nov 3, 2007
Messages
663
Location
Kent, UK
Programming Experience
10+
How can I remove the Microsoft.VisualBasic reference.
Go to your Solution Explorer and click on My Project. Select the References tab from the left, and you will see "Imported Namespaces" at the bottom. Microsoft.VisualBasic will be checked. Uncheck it :)
 

arsalangodil

Member
Joined
Dec 14, 2009
Messages
6
Programming Experience
Beginner
thnks for your help send2te.. but i didn't find any answer of my 2nd question.
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}


Dim MyDate As Date = DateSerial(2009, 12, 14)

Dim StartDate As Date = New Date(MyDate.Year,MyDate.Month,1)

Dim EndDate As Date = New Data(MyDate.Year,MyDate.Month,date.DaysInMonth(MyDate.Year,MyDate.Month))
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
Go to your Solution Explorer and click on My Project. Select the References tab from the left, and you will see "Imported Namespaces" at the bottom. Microsoft.VisualBasic will be checked. Uncheck it :)

I can see different references like:

System.Data
System.Drawing
System.Windows.Forms
etc

But Microsoft.VisualBasic is not available in the list.
 
Top Bottom