neoDate Plugin (added neoDateDifference) - Forum

Forum Navigation
You need to log in to create posts and topics.

neoDate Plugin (added neoDateDifference)

Page 1 of 3Next

I have enhanced the neoDate plugin to enable developers to obtain the difference between two date objects. The result can be requested in Milliseconds, Seconds, Minutes, Hours, Days, Weeks, Months, Quarters or Years ... the (maximum) number of decimal points can also be specified.

Please download and install the new version of the (beta) plugin, and the updated Tutorial, and advise me about any errors or omissions.

Uploaded files:
  • You need to login to have access to uploads.
luishp, Vadim and Palamar have reacted to this post.
luishpVadimPalamar

@gaev

Cool! Thank you very much!!

Thank you Gaev !

Thank you @gaev

 

Thanks You Gaev !!!!

Thank you @gaev!! :)

Hi @gaev/,@luishp

One question.

It's possible to obtain this format (extracted from tutorial): "2009-03-19 4:34:15.123 am" "YYYY-MM-DD h:mm:ss.SSS a" in order to calculate differences, using Date and Time Input Objects ?. I can't find the way to format the output of the variables, or it's only possible using javascript ?.

date input object output is: "2020-11-10T03:00:00.000Z"

time input object output is: "1970-01-01T19:29:00.000Z"

I was using this taken from another post but again with no results because only give to me date / time without seconds or miliseconds.

BeginJS
$App.myvar1=$("#DateInput1").val();
$App.myvar2=$("#TimeInput1").val();
EndJS

The output of about combined with Date and Time Input Objects variables is:

date: 2020-11-10

time: 16:26

Best regards,

Sam

Well, using moments library i do this as start point:

BeginJS

var today = $App.dia1;
moment.locale ("es");
var dia1 = moment(dia1).format('YYYY-MM-DDTHH:mm:ss.SSS dddd');
$App.dia1 = dia1;

EndJs

output format:

Your date/Time: 2020-11-22T17:07:59.511 domingo

I guess this could be the way, the only problem with this is that i'm not getting the date that i put inside Date Object but the actual date.

Regards,

Sam

@lesanch take a look at the Time/Date commands on the Actions panel to get year, month, day, hour and minutes from the Date and Time objects.

Regards.

Uploaded files:
  • You need to login to have access to uploads.

Hola @luihp, perdona, debe ser por la versión que tengo que no veo justo esa parte de la hora.

Saludos,

Sam

Uploaded files:
  • You need to login to have access to uploads.

@lesanch esa parte fué añadida en la última actualización, me temo.
Ahora no tengo tiempo de buscarlo pero hay un código equivalente en JavaScript publicado en el foro.
Si encuentro el momento lo busco y publico el enlace aquí mismo.

Saludos!

@lesanch

date input object output is: "2020-11-10T03:00:00.000Z"
time input object output is: "1970-01-01T19:29:00.000Z"

Try this ...

... your outputs
SetVar "[myDate]" "2020-11-10T03:00:00.000Z"
SetVar "[myTime]" "1970-01-01T19:29:00.000Z"

... separate date components from time components
StrParse "[myDate]" "T" [myDateArray]
StrParse "[myTime]" "T" [myTimeArray]

... combine date component of first variable with time component of second variable
SetVar [myDateTime] "[myDateArray(0)]T[myTimeArray(1)]"
...AlertBox "myDateTime" "[myDateTime]" ""

... now create the required neoDate object
neoDateCreate [abcd] "[myDateTime]" "YYYY-MM-DDTHH:mm:ss.SSSZ"

... verify (optional)
neoDateAsString [abcd] "YYYY-MM-DD HH:mm:ss.SSS" [abcdStr]
AlertBox "abcdStr" "[abcdStr]" ""

Hope that was what you were trying to solve.

 

@lesanch, este es el enlace que te decía:
https://visualneo.com/forum/topic/consulta-sobre-entrada-de-hora

Saludos!

Hi @Luishp / @Gaev,

I will try your solutions.

Thank you very much,

Sam.

I am trying to read two dates and flag a warning if the first date is older than the second date.

The built in date difference cannot be used as the dates get older the number increases again (does not go into minus)

So I am using JScript

I have to set some values first to suit the input.

Variable [dateinexpire] is from a date field in a database. Example (2021-09-21)

StrParse [dateinexpire] "-" [datein]

setvar [YearIn] [datein(0)]
setvar [MonthIn] [datein(1)]
setvar [DayIn] [datein(2)]

SetVar [DateInput1] "[YearIn]-[MonthIn]-[DayIn]"
setvar [DateInput2] "[NAB.Year]-[NAB.MonthNum]-[NAB.DayNum]"

BEGINJS
var d1 = Date.parse("$App.DateInput1");
var d2 = Date.parse("$App.DateInput2");
if (d1 < d2) {
$App.ExpDays = 0;
}
ENDJS

I just need the app variable ExpDays to be O if the database date is older than today.

I know I have something wrong in the JScript reading the app variable as it works if I place dates into where the app variables go.

Any help?

 

@jason-roberts

Try this script ...

...SetVar "[expiryDateFromDB]" "2021-09-19"
SetVar "[expiryDateFromDB]" "2021-09-27"


neoDateCreate [expiryDateObject] "[expiryDateFromDB]" "YYYY-MM-DD"
... for verification purposes only
neoDateAsString "[expiryDateObject]" "YYYY-MM-DDTHH:mm:ss" [expiryDateString]

neoDateCreate "[nowTimeObject]" "" ""
... for verification purposes only
neoDateAsString "[abcd]" "YYYY-MM-DDTHH:mm:ss" [nowTimeString]

neoDateDifference [nowTimeObject] [expiryDateObject] "seconds" 0 [secondsDifference]

If [secondsDifference] < 0
   ... expired
   AlertBox "Expired" "ExpiryDate=[expirydateString]<br/>Now=[nowTimeString]<br/>SecondsDifference=[secondsDifference]" ""
Else
   Math "[secondsDifference]/(24*60*60)" 2 [daysDifference]
   AlertBox "Not Expired" "Expirydate=[expirydateString]<br/>Now=[nowTimeString]<br/>SecondsDifference=[secondsDifference]<br/>DaysDifferece[daysDifference]" ""
EndIf

If the product expires at midnight of the Expiry Date value stored in your Database, you will have to add 23 hours, 59 minutes and 59 seconds to the date (using the neoDateChange command).

Thank you very much.

I am getting an error on run. Code running as supplied. Date is hard coded for testing.

TypeError: Object doesn't support property or method 'includes'
at neoDateDifference

Is this line correct?

neoDateDifference [nowTimeObject] [expiryDateObject] "seconds" 0 [secondsDifference]

 

@jason-roberts:

TypeError: Object doesn't support property or method 'includes' at neoDateDifference

Looks like you have the older version of the plugin ... as noted in the first post of this topic, an enhanced version (additional commands) was released after the original plugin.

Can you provide the version numbers of your VisualNeoWeb and neoDate plugin ?

 

 

@gaev Thanks for this plugin.

I would like to know if it is possible to get the name of months and days in the language of the application ?

I also noticed an error on the last but one page of the tutorial : Error: dateObjectVariable is not a valid date object

 

@phil78

I would like to know if it is possible to get the name of months and days in the language of the application ?

On the page labelled neoDateGet, I have a button labelled dayOfWeekName ... the code associated with it is ...

SetVar "[thisComponent]" "dayOfWeek"
neoDateGet [gkDateObject] "[thisComponent]" [gkDateComponent]

... translate number to name
SetVar [daysOfTheWeekLongForm] "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
StrParse "[daysOfTheWeekLongForm]" "," [daysOfTheWeekArray]
SetVar [thisDayOfTheWeek] "[daysOfTheWeekArray([gkDateComponent])]"
AlertBox "[gkDateString]" "dayOfWeekName = [thisDayOfTheWeek]" ""

So, in order to get the name of the month, the code would look something like ...

SetVar "[thisComponent]" "month"
neoDateGet [gkDateObject] "[thisComponent]" [gkDateComponent]

... translate number to name
SetVar [monthsOfTheYearLongForm] "January,February,March,April,May,June,July,August,September,October,November,December"
StrParse "[monthsOfTheYearLongForm]" "," [monthsOfTheYearArray]
SetVar [thisMonthOfTheYear] "[monthsOfTheYearArray([gkDateComponent])]"
AlertBox "[gkDateString]" "monthOfYearName = [thisMonthOfTheYear]" ""

In order to get names in different languages (or even abbreviations), just setup the LongForm variables as desired.

I also noticed an error on the last but one page of the tutorial : Error: dateObjectVariable is not a valid date object

1) please check that you have the latest version of the plugin.

2) please provide the name of the page (also in the Header at run time) and the label of the Button that is displaying the error.

 

Page 1 of 3Next