Cast Now() to a Number

The following works in ACF and Lucee, but not BoxLang (cfml-compat)

local.ver = (Now() * randRange(1,10,“SHA1PRNG”)) produces: Can’t cast [{ts ‘2025-06-02 10:40:12’}] to a Number.

Is that by design or did I stumble onto a compat issue?

@jclausen can you check comapt on this

Gary. I think this is really a problem with both cfml engines. As they don’t tell you which part of the date is being multiplied. Meaning is it in days. In minutes. In seconds. In nanoseconds.

In all reality. I think this type of code should have never been allowed.

1 Like

This should be handled in the latest version of cfml-compat. @gknight can you dump server.boxlang and let me know which version of bx-compat-cfml you are using?

boxlang 1.2.0+38
bx-compat-cfml 1.27.0+35

I think we are going to need more context. It’s working on TryCF with the lastest BoxLang version and compat module.

Could you paste the code block around this?

Oops. Looks like my form got reset and I can see the error now. Let me dig in to this a bit.

OK. @bdw429s Added support for the plus math operation on DateTime values in BL-896, but support for the other mathematical operations was not added. I’ve created BL-1501 to address this.

A PR is open now which should address this BL-1501 Resolve - add support for date math with *,-, and / by jclausen · Pull Request #214 · ortus-boxlang/BoxLang · GitHub

The snapshot with this fix is building now.

I’m mostly curious as to why one would multiply a date times a random number…

I use it as a way to force JavaScript or CSS changes to download when I make changes to them by assigning that random number to an application variable and placing it at the end of the file as a ‘version’ change. The browser treats it as a new file and downloads it to the cache. It may not be the best approach, but it works with minimal overhead.

I got the idea from this blog post from Ben Nadel.

Caching ColdFusion Pages With Expires Header Value

I could accomplish the same thing by using createUUID() in the same way, I just haven’t had a reason to change it.

Ah, okay. We do this:
<script src="/includes/javascript/views/billing/invoice.js?version=#getSetting('ReleaseVersion')#"></script>

And in our dev environments, the “release version” is randomized each request. Similar to what you’re doing…

1 Like

It’s a good technique. Thanks for sharing.