Announcement

Collapse
No announcement yet.

Comparing dates in Miva

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Comparing dates in Miva

    Hello!

    I'd like to have some sort of expression that looks something like <mvt:if expr="{product_custom_field_date} GT {todays_date}"> .... </mvt:if> but I'm not sure how best to compare dates in miva. First of all, how do you get today's date in mivascript? And then, is there a way to compare dates as a whole? According to http://www.mivascript.com/topic/time.html you can break out created_date time stamps into a readable format, or grab just the day, month, or year. But I already have the product custom field in a mm/dd/yyyy format so I don't know if those functions would even work with it?

    This would be easy in JS, but I don't think you can read/write to miva global/local variables quite so easily in JS (although correct me if I'm wrong).

    Thanks!

    #2
    You can pass global / local variables to JS as since their values would be evaluated at render time, so you could do something like
    Code:
    var my_date = new Date( '&mvtj:global:MyDate' );
    If you wanted to do it in MivaScript, you'd need to use the time_xxx builtin functions to convert the readable date to a UNIX timestamp. You could then do something like
    Code:
    <mvt:if expr="l.my_date GT s.dyn_time_t">
    ...
    </mvt:if>
    David Carver
    Miva, Inc. | Software Developer

    Comment

    Working...
    X