1

Topic: Difference of dates

There are two dates (one over the second). I want to learn a difference in between (in days). produces value "0". in variables vat1, vat2. Prompt how correctly to set them?

Sub ógv ()
Dim dat1 As Date
Dim dat2 As Date
Dim vat1 As Date
Dim vat2 As Date
Dim Day1 As Long
Dim Month1 As Long
Dim Year1 As Long
Dim Day2 As Long
Dim Month2 As Long
Dim Year2 As Long
Dim C As Range
Set A C = ThisWorkbook. ActiveSheet. Range ("C35")
' 1
dat1 = C.Value
Day1 = DatePart ("d", dat1)
Month1 = DatePart ("m", dat1)
Year1 = DatePart ("yyyy", dat1)
vat1 = Month1 / Day1 / Year1
' 2
dat2 = C.Offset (-1, 0).Value
Day2 = DatePart ("d", dat2)
Month2 = DatePart ("m", dat2)
Year2 = DatePart ("yyyy", dat2)
vat2 = Month2 / Day2 / Year2
Dni = DateDiff ("d", vat2, vat1)
MsgBox Dni
End Sub

2

Re: Difference of dates

maxim863 wrote:

vat1 = Month1 / Day1 / Year1

And what you try to receive, dividing a month for day and for a year?

3

Re: Difference of dates

maxim863 wrote:

I Want to learn a difference in between (in days)

https://msdn.microsoft.com/ru-ru/vba/la … f-function

4

Re: Difference of dates

And what for date should be assorted for day-month-year, and then to collect (and as correctly specified Shocker. Pro , through one place) it is reverse?
Subtract at once...

5

Re: Difference of dates

Akina;
Problem in that date (11/27/2017), . (..), and in vba .., therefore also I assort

6

Re: Difference of dates

maxim863 wrote:

Akina;
The problem in that date (11/27/2017), . (..), and in vba .., therefore also I assort

the Problem that you do not understand, than differs data type (date, a line), from date formatting. Formatting of date in the form of a line has no relation to data storage in data type Data.
If in a cell at you type "Date" in a variable of type Date you will receive DATE and you can do over it operations

7

Re: Difference of dates

Shocker. Pro;
I want to set date, type #27.11.2016# through variables, simply I do not know as correctly it to make

8

Re: Difference of dates

For an illustration: in four cells the same value, simply different format of cells lies.

9

Re: Difference of dates

maxim863 wrote:

I want to set date, type #27.11.2016# through variables, simply I do not know as correctly it to make

to Do it is necessary nothing.

dat1 = C.Value

in dat1 date already lies

10

Re: Difference of dates

Shocker. Pro;
I so tried to do, it is impossible, because
(A problem that date (11/27/2017), . (..), and in vba ..)

11

Re: Difference of dates

maxim863 , you Russian on the white told that VALUE and its DISPLAY are different things. Do not nod on the second, for the first all the same not such what you it see.

12

Re: Difference of dates

maxim863 wrote:

in vba ..

it concerns ONLY date LITERALS
In this case you  do not enter date, therefore to you on it to spit.
The unique problem here can be that at you date, and the text is stored in a cell  in the form of date not. But also in this case the problem dares parsing, and at all how you conceived.
To check up this version and to help possible it is not represented, as you did not lay out an ex-fur-tree-file

13

Re: Difference of dates

Shocker. Pro;
All is true, date in in a cell is result of parsing (i.e. the text) Sense to spread an ex-fur-tree a file till now I do not see

14

Re: Difference of dates

maxim863 wrote:

Sense to spread an ex-fur-tree a file till now I do not see

Well be picked itself then, times you do not see.

15

Re: Difference of dates

Shocker. Pro;
Was constructively

16

Re: Difference of dates

Dni = Cells (36, 3).Value - Cells (35, 3).Value

17

Re: Difference of dates

maxim863 wrote:

it is is constructive

That is constructive you consider to force us to guess, what there at you for the initial data, thus not to stir a finger to lay out a test file with pair lines that your problem has been solved for a minute?

18

Re: Difference of dates

maxim863 wrote:

Sense to spread an ex-fur-tree a file till now I do not see

Pfff... At you a problem, not at us... You can and sit further on the file, perhaps the decision itself ...

19

Re: Difference of dates

Shocker. Pro,

20

Re: Difference of dates

Akina;
Time, you insist

21

Re: Difference of dates

Dim split1 As Variant, dat1 As Date
split1 = Split (Range ("C35").Text, ".")
dat1 = DateSerial (split1 (2), split1 (1), split1 (0))
MsgBox dat1

22

Re: Difference of dates

maxim863 wrote:

Time, you insist

here till now argues, you look
That to me to write the above-stated code, it was necessary for me the nobility in what format at you this date, what separator is used. Not obviously unless?

23

Re: Difference of dates

Shocker. Pro;
Thanks, work!
I apologize for