Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Increment date field

Hi,

How can I increment the date field by 1? Assuming the best way to do this is a macro then how do i finish this sub...

sub inc()
set f = ActiveDocument.GetField ("Date")
f.select ???????
End sub

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I wouldn't mess with VB functions. Easier to use QV functions with Evaluate().


'Select today.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("today(1)")

'Select tomorrow
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(today(1)+1)")

'Select 5 days from current selection.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(only(Date)+5)")


-Rob

View solution in original post

7 Replies
Not applicable
Author

By increment the date, do you mean select tomorrow?

If so, you can use the VBScript function DateAdd: f.select DateAdd("d", 1, Day())

I tried to test it out and my fields have timestamps, which didn't want to cooperate. This should work fine if your values are dates only.

Not applicable
Author

No i mean more broadly increment by n days.

Using your code I get an error on the

f.



select DateAdd("d", 1, Day())

Wrong number of arguments or invalid property assignment: 'Day'

Thanks



rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


Alkaline wrote:i mean more broadly increment by n days


A date is stored as number of days since the epoch date. To increment by n days, add n.

-Rob

Not applicable
Author

Yes which is what (in principle) that code does.

But to clarify, the code doesn't work and I'm not sure why:

sub inc()
set f = ActiveDocument.GetField ("Date")
f.select DateAdd("d", 1, Day())
End sub

i tried this instead

f.select DateAdd("d", 1, Day(myselection.Item(0).text))

That compiles, but it doesn't change the date

Not applicable
Author

I'm sorry, the VB Script function is Date() not Day().

As Rob said, you probably don't need to bother with DateAdd (old habit). Just add, so: f.Select Date() + n.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I wouldn't mess with VB functions. Easier to use QV functions with Evaluate().


'Select today.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("today(1)")

'Select tomorrow
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(today(1)+1)")

'Select 5 days from current selection.
ActiveDocument.GetField("Date").Select ActiveDocument.Evaluate("date(only(Date)+5)")


-Rob

Anonymous
Not applicable
Author

Hi,

I have a problem similar to this, but couldn't solve it with your tips (yet).

Could you have a look?

http://community.qlik.com/forums/t/31069.aspx

Thanks,