INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Expression help using now() and math()  (Read 707 times)

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Expression help using now() and math()
« on: August 29, 2019, 05:07:56 pm »

I want to set up a new field that takes the current time and adds the duration of a movie/TV show to display what time the movie/show will end.

For the life of me I can't get it figured out. 

I have this
Code: [Select]
math(now() + ([Duration,0]))
Which I believe is giving me the correct floating point number (I think that's the right terminology).  I setup a now() expression column and another one right next to it using the code above and the second column it a larger value, so it looks like it's doing math anyway.

The problem is whenever I try and incorporate formatdate() I get some weird results.

As an example, I tried

Code: [Select]
FormatDate(math(now() + (  [Duration,0])),h:mm)
And all that does is return the current time.

Any help would be appreciated. 
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Expression help using now() and math()
« Reply #1 on: August 29, 2019, 06:48:18 pm »

The problem here is the Duration field format.  In "raw" form it is in seconds.  But MC's internal date format is a bit unusual.  It represents days as integer days since the epoch.  The decimal part of an MC "date" is the hours, minutes, and seconds represented as a decimal.  So 12 noon is "0.5". 

Thus, you need to divide seconds by the number of seconds in a day in order to get the correct fraction.  That will then add correctly and give you end end time you desire.  This expression works:

Code: [Select]
FormatDate(math(now() + ([Duration,0]/86400)),hh:mm)
Brian.
Logged

Moe

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 695
  • Hi
Re: Expression help using now() and math()
« Reply #2 on: August 29, 2019, 08:43:13 pm »

That works perfect.

Thank you!  I highly doubt I would have ever gotten there on my own. 
Logged

blgentry

  • Regular Member
  • Citizen of the Universe
  • *****
  • Posts: 8009
Re: Expression help using now() and math()
« Reply #3 on: August 30, 2019, 07:10:37 am »

You are welcome.

I think you would have eventually gotten it.  You seem to understand MC and the expression language pretty well. 

Anyway, glad to have helped with a neat idea.

Brian.
Logged

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Expression help using now() and math()
« Reply #4 on: August 31, 2019, 07:41:35 am »

Good idea, Moe.
Countries which are using comma separator with number will also need to use Replace() function to change commas to periods as Math() only accepts periods as decimal separator.
So:
FormatDate(Math(Replace(Now(),/,,.) + (Replace([Duration,0],/,,.)/86400)),HH:mm)

Using "HH" here instead of "hh" makes MC use 24h clock. Choice is yours
Logged

arcspin

  • Galactic Citizen
  • ****
  • Posts: 379
Re: Expression help using now() and math()
« Reply #5 on: August 31, 2019, 02:00:39 pm »

This is great,
I used this expression with great success: FormatDate(Math(Replace(Now(),/,,.) + (Replace([Duration,0],/,,.)/86400)),HH:mm)
I live in Sweden.

Many thanks to Moe for a great idea and lepa and blgentry for a perfect expression.


I love JRiver and all the great people in this forum!
Logged
Hardware: Intel Core i5-8600K 16GB RAM, ASUS GeForce RTX 2080 8GB DUAL OC
Software: Windows 10 Home 64-bit, version 2004, JRiver MC 29, MadVr 0.92.17 (Beta 113), NVIDIA driver 457.09
Projector: JVC DLA-I X5500 (RS420, X570R) -
Screen: DNP Supernova 08-85
Processor: Anthem AVM 70
Power amp: XTZ A2-400 for Front & Center - XTZ A2-300 for Surround & Height channels
Speakers: Arendal 1723 S Monitor for Front & Center, Linn Unik for Front Height, Rear Height, Surround & Surround back. Elipson Planet M for Top Middle.
Sub: Arendal 1723 1S

lepa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1971
Re: Expression help using now() and math()
« Reply #6 on: August 31, 2019, 02:18:01 pm »

Cool! That black and red reminds me somehow of 80's stereo leds and such. In a good way of course :)
Logged

thorsten

  • World Citizen
  • ***
  • Posts: 194
Re: Expression help using now() and math()
« Reply #7 on: September 01, 2019, 02:53:27 pm »

Fantastic new feature, you guys are awesome!
Logged

james.smth

  • Recent member
  • *
  • Posts: 7
Re: Expression help using now() and math()
« Reply #8 on: September 03, 2019, 03:03:12 pm »

I use it like this:
Code: [Select]
FormatDate(Math(Replace(Now(),/,,.) + (Replace([Duration,0],/,,.)*(100-[Progress Percent])/8640000)),HH:mm)
Where [Progress Percent] is [Bookmark Percent] from this thread: https://yabb.jriver.com/interact/index.php/topic,85974.0.html
Logged
Pages: [1]   Go Up