current date at run-time...

S

Scott

I have a start date and an end date in my project that is defaulted to the current date at run-time using the following code...

Date1.Value = Now()

Date2.Value = Now()

I then have some code that works out the number of days between the 2 dates as follows...

Dim d1, d2 As Date

d1 = Me.Date1.Value

d2 = Me.Date2.Value

Me.TextBox7.Text = CStr(d2.Subtract(d1).Days)

The problem that I am having is if I don't change the first date but change the second date to 1 day from now it doesn't pick up that it is 1 day apart! But if I select the first date physically and change it to the day that is automatically displayed at run time then this works correctly but realising that it is 1 days difference! (hope you understand this!).

Maybe this will help you understand... If the default start date is today 03/03/05 and I change the end date to 04/03/05 then the code still says 0 days difference between the days. But if I physically select 03/03/05 as the start date and select 04/03/05 as the end date then the code tells me that the difference is 1 day!???

Why is this code not working correctly in this instance and is there a work-around???

Hope you all understand

Regards Scott
 
V

VJ

Scott , are you saying that it works from UI change (i.e using a DateTimePicker control), but not if you change it programatically?

VJ
I have a start date and an end date in my project that is defaulted to the current date at run-time using the following code...

Date1.Value = Now()

Date2.Value = Now()

I then have some code that works out the number of days between the 2 dates as follows...

Dim d1, d2 As Date

d1 = Me.Date1.Value

d2 = Me.Date2.Value

Me.TextBox7.Text = CStr(d2.Subtract(d1).Days)

The problem that I am having is if I don't change the first date but change the second date to 1 day from now it doesn't pick up that it is 1 day apart! But if I select the first date physically and change it to the day that is automatically displayed at run time then this works correctly but realising that it is 1 days difference! (hope you understand this!).

Maybe this will help you understand... If the default start date is today 03/03/05 and I change the end date to 04/03/05 then the code still says 0 days difference between the days. But if I physically select 03/03/05 as the start date and select 04/03/05 as the end date then the code tells me that the difference is 1 day!???

Why is this code not working correctly in this instance and is there a work-around???

Hope you all understand

Regards Scott
 
S

Scott

Kind of... read me notes carefully I think it just about makes sense!

Basically if I do not touch the 'start date'(date1) and change the 'end date'(date2) it still thinks the difference is 0 days! But if I manually select 'start date'(date1) <as the same date is was anyway> and select the 'end date'(date2) as 1 day later it does successfully realise that the date difference is 1 day! Must be a bug in the system???

Scott
Scott , are you saying that it works from UI change (i.e using a DateTimePicker control), but not if you change it programatically?

VJ
I have a start date and an end date in my project that is defaulted to the current date at run-time using the following code...

Date1.Value = Now()

Date2.Value = Now()

I then have some code that works out the number of days between the 2 dates as follows...

Dim d1, d2 As Date

d1 = Me.Date1.Value

d2 = Me.Date2.Value

Me.TextBox7.Text = CStr(d2.Subtract(d1).Days)

The problem that I am having is if I don't change the first date but change the second date to 1 day from now it doesn't pick up that it is 1 day apart! But if I select the first date physically and change it to the day that is automatically displayed at run time then this works correctly but realising that it is 1 days difference! (hope you understand this!).

Maybe this will help you understand... If the default start date is today 03/03/05 and I change the end date to 04/03/05 then the code still says 0 days difference between the days. But if I physically select 03/03/05 as the start date and select 04/03/05 as the end date then the code tells me that the difference is 1 day!???

Why is this code not working correctly in this instance and is there a work-around???

Hope you all understand

Regards Scott
 
C

Cor Ligthert

Scott,

Because probably what you want to do is

Dim d1, d2 As Date
d1 = Me.Date1.Value
d2 = Me.Date2.Value
Me.TextBox7.Text = CStr(d2.date.Subtract(d1.date).Days)

I showed that already in my message about your question about the
datetimepicker. However you ignored my answer and took Jay's.

You are now subtracting parts of 100 nanoseconds (ticks) and translate those
to days.

Cor
 
S

Scott

OK Cor.

Didn't mean to offend, just used the other one for no reason. Now the
problem has come about I can try your code out...

Cheers I'll see it goes...

Scott
 
C

Cor Ligthert

Scott,

It was not offending by nobody, however I had written why I told it like
this and nobody gave a reaction, so I was a little bit disapointed.

Cor
 
S

Scott

You were right to say that too. To be honest with you I completely
overlooked it! But you did call it!!!

Congrats

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top