24/7 Support: 800.608.6482

Videos

Try our new AI assistant by clicking the chat icon in the lower right corner.

Developer Videos

Videos | Time Functions

ver. 9.0 and later

Video Transcript

Mivascript, the core programming language that Miva Merchant is written in, has a bunch of functions that are related to time. Because you can access these functions within the template language using mvt:assign and mvt:eval, we have access to all these time functions as well, to manipulate and reformat unix time stamps to human readable dates and times. While it’s not very common that you’ll need to use these functions within the template language, it’s important to note that they exist. I want to take a look at one quick example of how to convert a unix time stamp to a human readable date and time format.

Here I have three variables for month, day and year. The variable that we’re actually patching into this is this l.settings:admin_order:orders[1]:orderdate. Now this is an array of orders. That’s why you see this index1, but really all this is is a Unix time stamp for a specific order. Here, what we want to do is take that Unix time stamp and convert it to a month, a day and a year. Once we have those variables in a template language, and we can format it in any human readable date we like.

So there are a few functions here that are being combined together to give us what we need. The first one here is this time_t_month. This will convert a Unix time stamp to an actual month. This has two parameters; the Unix time stamp that we talked about and this time zone parameter which we’re passing in the key of local. Now the time zone parameter is the offset from gmt time and local will actually calculate that offset for you based on the server time. So that’s the first function and the second function is this padl, which means it’s padding left and the two parameters after that are two digits and we’re going to pad it left with 0’s. That’s just so we get 01, 02, 03, etc. Now that same concept it applied to day, but instead of time_t_month we have time_t_dayofmonth and it’s exact same parameters get passed in. Then for the year we have time_t_year and we don’t need to pad this because it will always return a four digit year. What we end up with here is we have a two digit month, a two digit day and a four digit year as variables within the template language that we can then format with any date we would like.



Example Code

Reference Documentation




Looking for Developer Docs?

We have a whole section for that, including: Developer Training Series, Template Language docs, Module Development tutorials and much, much more.

Head to the Developer Section

Copyright © 1997 – 2024 Miva®, Miva Merchant®, MivaPay®, MivaCon®, Camp Miva®, Miva Connect®, Miva, Inc. All Rights Reserved.