473,473 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determining Future Date

I am trying to write a function that determines how many hours there are
until a certain date/time that depends on what today's date/time is.

Basically, how many hours from now until the next time that it is 8am on
Monday.

I've found the dateadd, hour, and weekday functions, but I can't seem to
get it straight in my head how to use them in this case.

Nov 13 '05 #1
6 2040
On Thu, 09 Sep 2004 22:27:40 GMT, HateSpam <Ha******@nospam.com>
wrote:
I am trying to write a function that determines how many hours there are
until a certain date/time that depends on what today's date/time is.

Basically, how many hours from now until the next time that it is 8am on
Monday.

I've found the dateadd, hour, and weekday functions, but I can't seem to
get it straight in my head how to use them in this case.


Use DateDiff. Try this in the immediate window.

?DateDiff("h",Now(),#9/13/04 8:00 AM#)
88

So, as I write this there are 88 hours until next monday 8 AM.

- Jim
Nov 13 '05 #2
Jim Allensworth wrote:
On Thu, 09 Sep 2004 22:27:40 GMT, HateSpam <Ha******@nospam.com>
wrote:
I am trying to write a function that determines how many hours there are
until a certain date/time that depends on what today's date/time is.

Basically, how many hours from now until the next time that it is 8am on
Monday.


Use DateDiff. Try this in the immediate window.

?DateDiff("h",Now(),#9/13/04 8:00 AM#)
88

So, as I write this there are 88 hours until next monday 8 AM.


Thanks for your reply. Actually, I already got that much though.

The trick I am looking for is determining what value should be filled in
for #9/13/04# on the fly. It needs to calculate how many hours til the
next Monday at 8am depending on WHICH Monday that happens to be based on
the current day.

Nov 13 '05 #3
Hi,
Found a couple of datetime functions that might help. Try this. I tested
it in the Immediate Window.

Public Function DoMondayAtEight()
Dim hours As Integer
Dim nextMonday As Integer
Dim result As Integer

hours = Weekday(Now()) - 1
hours = hours * 24 + Hour(Now())
Debug.Print hours

nextMonday = (vbMonday - 1) * 24
nextMonday = nextMonday + 8
Debug.Print nextMonday

If hours <= nextMonday Then
result = nextMonday - hours
Else
result = ((7 * 24) - hours) + nextMonday
End If
Debug.Print result

End Function

Linda
"HateSpam" <Ha******@nospam.com> wrote in message
news:5M****************@fe1.columbus.rr.com...
Jim Allensworth wrote:
On Thu, 09 Sep 2004 22:27:40 GMT, HateSpam <Ha******@nospam.com>
wrote:
I am trying to write a function that determines how many hours there are
until a certain date/time that depends on what today's date/time is.

Basically, how many hours from now until the next time that it is 8am on
Monday.


Use DateDiff. Try this in the immediate window.

?DateDiff("h",Now(),#9/13/04 8:00 AM#)
88

So, as I write this there are 88 hours until next monday 8 AM.


Thanks for your reply. Actually, I already got that much though.

The trick I am looking for is determining what value should be filled in
for #9/13/04# on the fly. It needs to calculate how many hours til the
next Monday at 8am depending on WHICH Monday that happens to be based on
the current day.

Nov 13 '05 #4
Squirrel wrote:
Found a couple of datetime functions that might help. Try this. I tested
it in the Immediate Window.


[code snipped]

Perfect. You rock.

Nov 13 '05 #5
HateSpam <Ha******@nospam.com> wrote in message news:<5M****************@fe1.columbus.rr.com>...
Jim Allensworth wrote:
On Thu, 09 Sep 2004 22:27:40 GMT, HateSpam <Ha******@nospam.com>
wrote:
I am trying to write a function that determines how many hours there are
until a certain date/time that depends on what today's date/time is.

Basically, how many hours from now until the next time that it is 8am on
Monday.


Use DateDiff. Try this in the immediate window.

?DateDiff("h",Now(),#9/13/04 8:00 AM#)
88

So, as I write this there are 88 hours until next monday 8 AM.


Thanks for your reply. Actually, I already got that much though.

The trick I am looking for is determining what value should be filled in
for #9/13/04# on the fly. It needs to calculate how many hours til the
next Monday at 8am depending on WHICH Monday that happens to be based on
the current day.

I started on this. The "find the next monday" thing is easy. The
trick, I guess, is to check what the current date/time it is. Then if
it's Monday, you keep going. I'll post it later today.
You basically use a do loop and add a day to a temp date. And then
you check for meeting your criteria outside the loop and you're there.

HTH,
Pieter
Nov 13 '05 #6
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
HateSpam <Ha******@nospam.com> wrote in message news:<5M****************@fe1.columbus.rr.com>...
Jim Allensworth wrote:
On Thu, 09 Sep 2004 22:27:40 GMT, HateSpam <Ha******@nospam.com>
wrote:
>I am trying to write a function that determines how many hours there are
>until a certain date/time that depends on what today's date/time is.
>
>Basically, how many hours from now until the next time that it is 8am on
>Monday.

Use DateDiff. Try this in the immediate window.

?DateDiff("h",Now(),#9/13/04 8:00 AM#)
88

So, as I write this there are 88 hours until next monday 8 AM.


Thanks for your reply. Actually, I already got that much though.

The trick I am looking for is determining what value should be filled in
for #9/13/04# on the fly. It needs to calculate how many hours til the
next Monday at 8am depending on WHICH Monday that happens to be based on
the current day.

I started on this. The "find the next monday" thing is easy. The
trick, I guess, is to check what the current date/time it is. Then if
it's Monday, you keep going. I'll post it later today.
You basically use a do loop and add a day to a temp date. And then
you check for meeting your criteria outside the loop and you're there.

HTH,
Pieter


Hello -

Think this might return what you're after
Expand|Select|Wrap|Line Numbers
  1. Function FutureDate(Optional pTarget As Integer = vbMonday) As Integer
  2. Dim dteNow   As Date
  3. Dim dteNew   As Date
  4. Dim intDay   As Integer
  5.  
  6. dteNow = Now()
  7. intDay = pTarget
  8. dteNew = Int(dteNow - WeekDay(dteNow) + intDay + _
  9. IIf(WeekDay(dteNow) >= intDay, 7, 0)) + #8:00:00 AM#
  10. Debug.Print dteNew
  11. FutureDate = DateDiff("h", dteNow, dteNew)
  12.  
  13. End Function
  14.  
HTH - Imboden
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: asreryll | last post by:
I wish to show a future date in a table, so that I can sort and know which case is in need of a review. I can display a future date in a form but I want to see all records that are due on a certain...
28
by: ROSY | last post by:
1.How to make self deletable .exe file such that during runtime the file delete itself from the current path. plz answer, thanks in advence. bye.
6
by: rohayre | last post by:
Im a long time java developer and actually have never done anything with java scripting. I'd like to write a short simple script for calculating a date in the future based on today's date and a...
5
by: Kevin | last post by:
I have a simple application that handles authentication, and one of the things it checks is password aging. If I have something like this: If ("02/14/2007" <= Date.Today.ToString("MM/dd/yyyy"))...
2
by: bloukopkoggelmander | last post by:
Hi all Right, I dont know if this is possible in Access (2007) or not but here goes. I want to create a form for a vehicle delivery where a user completes say half of it before delivery of the...
2
by: =?Utf-8?B?Sm9ubnk=?= | last post by:
I have an ASP.NET 2.0 C# web application that is contacting an Exchange server using WEBDAV. It allows the users to look up appointments for a future date. The problem I have is determining the...
1
by: dkyadav80 | last post by:
Hi Sir, I'm begener in Ajax or Javascript.I have problem about date validation. I have 3 field in html page: 1->date(numeric), 2->month(text 1st 3 letter) 3->year(numeric). I wanna implement to...
4
by: drrajnishpatel via AccessMonster.com | last post by:
Dear Friends i am trying to get a future date as follows, data:1) date of proceeding to leave = D 2) number of days leave sanctioned =N 3) date of reporting for duty =R i grant "n" number of...
7
by: jmartmem | last post by:
Greetings, I have an ASP page with a form (form1) that contains a JavaScript validation function that is activated onSubmit. The function contains a series of IF statements to alert the user to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.