Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add days to existing date.....? 1

Status
Not open for further replies.

AuctionLamb

Programmer
Joined
Feb 16, 2005
Messages
65
Location
ZA
Hi Guys!!!

Me again, I get a date from a table field "receivedDate". "receivedDate" = 2005-02-23 14:39:07.797, In VB how do I add 4 days if the time is before 12 and 5 days after 12.

Help on this one would save my life!!

THANKS!
 
You'll have to remove the milliseconds at the end of the date for many (if not all) of the date functions in VB to work.

Harleyquinn

---------------------------------
For tsunami relief donations
 
Thanks!

But I need someone to show me how I will do it? I know how to add a 4 or 5 days but how do I check if the day is before 12 or after 12 to add the required date amount?
 
Something like:
Code:
If Format(YourDate, "HH") > 12 Then
NewDate = DateAdd("d", 5, YourDate)
Else
NewDate = DateAdd("d", 4, YourDate)
End If
That works for me.

Harleyquinn

---------------------------------
For tsunami relief donations
 
THANKS!!!

Works like bomb!! Just one simple thing though.....how do I strip the milliseconds off the date value?
 
Thanks!!

Thank was quite simple!!! Think that my brain is fried by now because working through the night for 2 days to make deadline!!!
 
No need to use DateAdd. Adding days is the simplest thing that can be done to a Date variable.
___
[tt]
Dim receivedDate As Date
receivedDate = #2/23/2005 2:39:07 PM#
If Hour(receivedDate) < 12 Then
receivedDate = receivedDate + 4
Else
receivedDate = receivedDate + 5
End If
MsgBox receivedDate[/tt]
 
OK.....now the client asks for not just 4 or 5 days but 4 or 5 working days? How do I do that with the code:

If Format(YourDate, "HH") > 12 Then
NewDate = DateAdd("d", 5, YourDate)
Else
NewDate = DateAdd("d", 4, YourDate)
End If
 
Might not be the best (or shortest) way to do it but you could do it with a case statement. Something like:
Code:
Select Case Format$(date1, "dddd")

Case "Monday"
    If Format(YourDate, "HH") > 12 Then
    NewDate = DateAdd("d", 7, YourDate)
    Else
    NewDate = DateAdd("d", 4, YourDate)
    End If
Case "Tuesday"
    If Format(YourDate, "HH") > 12 Then
    NewDate = DateAdd("d", 7, YourDate)
    Else
    NewDate = DateAdd("d", 6, YourDate)
    End If
etc...

Hope this helps


Harleyquinn

---------------------------------
For tsunami relief donations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top