I Inman Well-Known Member Licensed User Longtime User Nov 26, 2011 #1 Visual Basic has this function called Datediff that shows number of days between 2 dates. I am looking for a similar function in B4A. I see that B4A has DateTime.Add but it sounds more like adding (or subtracting) days to a certain date to get the new date. I need the reverse. Is it possible?
Visual Basic has this function called Datediff that shows number of days between 2 dates. I am looking for a similar function in B4A. I see that B4A has DateTime.Add but it sounds more like adding (or subtracting) days to a certain date to get the new date. I need the reverse. Is it possible?
rbsoft Active Member Licensed User Longtime User Nov 26, 2011 #2 Yes. From the helpfiles (B4A Helpviewer): Pass negative values if you want to subtract the values. Example: Code: Copy Dim Tomorrow As Long Tomorrow = DateTime.Add(DateTime.Now, 0, 0, 1) Log("Tomorrow date is: " & DateTime.Date(Tomorrow)) Upvote 0
Yes. From the helpfiles (B4A Helpviewer): Pass negative values if you want to subtract the values. Example: Code: Copy Dim Tomorrow As Long Tomorrow = DateTime.Add(DateTime.Now, 0, 0, 1) Log("Tomorrow date is: " & DateTime.Date(Tomorrow))
I Inman Well-Known Member Licensed User Longtime User Nov 26, 2011 #3 Thank you, but that doesn't accept 2 days and show their difference. For example I have 25/11/2011 and 26/11/2011. I need a function to subtract 25/11/2011 from 26/11/2011 so that the answer is 1. In DateTime.Add, I can only subtract 1 from 26/11/2011 so that the answer is 25/11/2011. I need the opposite. Upvote 0
Thank you, but that doesn't accept 2 days and show their difference. For example I have 25/11/2011 and 26/11/2011. I need a function to subtract 25/11/2011 from 26/11/2011 so that the answer is 1. In DateTime.Add, I can only subtract 1 from 26/11/2011 so that the answer is 25/11/2011. I need the opposite.
rbsoft Active Member Licensed User Longtime User Nov 26, 2011 #4 Ok, I understand. That also is not too difficult. You could use a function like this; Code: Copy Dim tks, d, h, m, s As Long tks = DateTime.DateParse("06/15/2011") - DateTime.DateParse("06/05/2011") d = tks / DateTime.TicksPerDay ToastMessageShow(d, True) The result will show you that the difference is 10 days. Rolf Upvote 0
Ok, I understand. That also is not too difficult. You could use a function like this; Code: Copy Dim tks, d, h, m, s As Long tks = DateTime.DateParse("06/15/2011") - DateTime.DateParse("06/05/2011") d = tks / DateTime.TicksPerDay ToastMessageShow(d, True) The result will show you that the difference is 10 days. Rolf
I Inman Well-Known Member Licensed User Longtime User Nov 26, 2011 #5 Somehow I missed TicksPerDay when I checked out the documentation. I was wondering all along how to reverse a tick to readable date. Thanks for the help mate. Upvote 0
Somehow I missed TicksPerDay when I checked out the documentation. I was wondering all along how to reverse a tick to readable date. Thanks for the help mate.