Excel VBA Basics #23 DATEADD - Add or Subtract Minutes, Months, Weekdays, Seconds whatever!!

preview_player
Показать описание

This is the super duper cheater way to easily calculate what a date or time might be like when you add or subtract a certain amount of time. You can add 3 months, or 15 quarters, or 7134.5 hours. Here's what you can add or subtract:

s Seconds
n Minutes
h Hours
d Days
w Weekdays
ww Weeks
m Months
q Quarters
y Days of the year
yyyy Years

so to add 1234 seconds to the current time would be
answer = DateAdd( "s", 1234, Time) ' because Time is default system time variable.

To get 34 quarters ago,
answer = DateAdd("q", -34, Date) ' because Date is default system date variable.

So. . .
answer= DateADd("m", 25, "11:00 AM")
answer would have the value 11:25 AM
w Weeks

Fantastic Developer Tools:
Рекомендации по теме
Комментарии
Автор

Merry Christmas everyone. I hope God blesses you richly this upcoming year. Remember, you ARE a success!! Believe it, be it! Blessings my friends!! Dan

ExcelVbaIsFun
Автор

Super Super Super Super 😘😘😘😘👍👍👍👍
Only you tell me how to add dates
Found exactly
thank you

ESongslk
Автор

to put stDate to equal a date value you put tow # around the date expression:
Example: stDate = #12/31/2005#
good luck

MohammadTaha
Автор

This is magic. What I am looking for. Thanks

talkstop
Автор

no equation. Check out my video on loops by searching on my channel. But when you create a 'FOR/NEXT' loop, you say For X = (starting number) to (ending number)


'put your code here that involves the escalating variable, in this case x


then add Next x at the bottom.

Everything in between the FOR part at the top and the NEXT part at the bottom happens over and over again until x has exceeded the ending number.

ExcelVbaIsFun
Автор

How was the meaning of the word "Quarter" captured by the table of text?
Are the values in the explanation column actual values in VBA? (like "true" for example?)

Thanks for the great vids!

danjtitchener
Автор

One question:
I have different frequency types (e.g: semi-annual, every 3 months). Is there any work around to use these frequencies with the DateAdd function?

iAhmad_Q
Автор

Good night in cycle in vba for next I want in a loan system to bring me the installments daily modality, example 20 installments that start on 01-10-22 and I want 20 installments but exclude Sundays and the 20 installments are fulfilled, what would be the code

miguelangelvalladaressanta
Автор

i try to make a comment before Debug.Print stdate, however, there is no response from immediate window, why is it?
So next time to make immediate window works, i need to include Debug.Print in my code?

darwinchan
Автор

Hi Dan, Working with Dates gives an error on my vba macbook. How do i get my vba to recognise the dates?

jessli