ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Add Number to variable date (https://www.excelbanter.com/excel-programming/425605-add-number-variable-date.html)

bijan

Add Number to variable date
 
Hi Experts,
I have a variable for date that calls in SQL for cut of time :
Vardate1= Format(Me.TextBox1.Value, "DD MMM YYYY")
:
:
" AND (Table1.DATE_SCH='" & Vardate1 & "'" & _
What I need is how add 180 days to this cut of time automatically, I tried :
AND (Table1.DATE_SCH='" & Vardate1 & "' + 180" & _
But I didn't get proper date,
Thanks in advance for any help
Bijan


Jacob Skaria

Add Number to variable date
 
Dear Bijan

Try the below code and make sure you have declared the variable varDate1 as
Date

'" & Vardate1 + 180 & "'

If this post helps click Yes
---------------
Jacob Skaria


bijan

Add Number to variable date
 
Hi Jacob,
I tried your code and get type mismatch error, It seems property of vardate1
isn't date and as I mentioned It set to:
vardate1 = Format(Me.TextBox1.Value, "DD MMM YYYY")
Bijan

"Jacob Skaria" wrote:

Dear Bijan

Try the below code and make sure you have declared the variable varDate1 as
Date

'" & Vardate1 + 180 & "'

If this post helps click Yes
---------------
Jacob Skaria


Jacob Skaria

Add Number to variable date
 
You can convert varDate1 to date and then add..

CDate(varDate1) + 180

If this post helps click Yes
--------------
Jacob Skaria

Doug Robbins - Word MVP on news.microsoft.com

Add Number to variable date
 
Use the DateAdd function

Vardate1 = Format(DateAdd("d", 180, Me.TextBox1.Value), "dd MMM yyyy")
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"bijan" wrote in message
...
Hi Experts,
I have a variable for date that calls in SQL for cut of time :
Vardate1= Format(Me.TextBox1.Value, "DD MMM YYYY")
:
:
" AND (Table1.DATE_SCH='" & Vardate1 & "'" & _
What I need is how add 180 days to this cut of time automatically, I tried
:
AND (Table1.DATE_SCH='" & Vardate1 & "' + 180" & _
But I didn't get proper date,
Thanks in advance for any help
Bijan





All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com