Problem Getting Warranty End Date Correct Dd/mm/yy 追蹤

0
Avatar
Legacy Poster

Hi,

  I'm new to the forums but this problem has driven me here out of desperation.  We have tags developed offsite for various customers and this one used to be simple until they changed their warranty date requirements.

  The Begin date is the Current day + 7 days, in format dd/mm/yy.  Easy enough in Bartender.

 

The problem we are having is the end date.  It is specified as Begin date + 3 years 2 months, in format dd/mm/yy.  We have yet to be able to get a working solution for this that is right all the time.  We've set the Begin date as a Share name WarDate and the month of the Begin as WarMonth.  

The End date has just the dd+7 days first, then a script for the month and year.  Obviously, today (July 24) plus 2 months 7 days shouldn't be September 31.  We then have a script for the Month:

 

Dim MyMonth
 
MyMonth = WarMonth + 2
 
If MyMonth = 13 then MyMonth = 1
If MyMonth = 14 then MyMonth = 2
 
If len(MyMonth) < 2 then MyMonth = "0" & MyMonth
 
Value = MyMonth
 
That seems to work alright.  Then the script for the Year.
 
Dim MyMonth
Dim MyYear
 
MyMonth = Month(Date)
MyYear = Year(Date) + 3
 
If WarMonth >= 11 Then MyYear = MyYear + 1 
    'May change year to 4 digits, depending on the system date format settings.
 
Value = Replace(MyYear, Right(MyYear, 4), Right(MyYear, 2))
    'This expression replaces the last 4 digits of the date with the last 2 digits of the date, changing the year format to a 2 digit year.
 
This also seems to work.  But all of it together results in our End date being 31/09/17.  Since September is only 30 days we have a problem.

 

I've attached one of the templates to see if anyone can help.  It's the combination of the multiple date additions and the specific date format that is our problem.  

Also, I'm in the US so that is not my default date format and I can't change my system date format for just this one tag.

 

Any help is greatly appreciated as we've had numerous people try at this and it's still not 100%.

 

 

Paul

 

1 意見

0
Avatar
Shotaro Ito
評論操作 永久連結

Hi Paul,
To add date, use DateAdd vbs function.

'get todays date'
dateToday = Now()

'add 7 days, then 3 years, then 2 months'
dateBegin = DateAdd("d",7,dateToday)
dateBegin3yrs = DateAdd("yyyy",3,dateBegin)
dateEnd = DateAdd("m",2,dateBegin3yrs)

'reformat to dd/mm/yy'
dd = Right("0" & Day(dateEnd),2)
MM = Right("0" & Month(dateEnd),2)
yy = Right(Year(dateEnd),2)
Value = dd & "/" & MM & "/" & yy

--
Good news - you can do that without VB Script, in Ver 10.0 or later.
Note that you need 3 text to do that:

Text1: Clock(today) : Type Date : Offset 7 days
Text2: Object value of Text1 : Type Date: Offset 3 years
Text3: Object value of Text2 : Type Date(Format custom dd/MM/yy) : Offset 2 months

hide Text1 and Text2 as these are interim object.

登入寫評論。