// Convert a string to a date variable
dateAsString = "03/12/2024 03:15:35";
dateObject = totime(dateAsString, "dd/MM/yyyy hh:mm:ss");
info dateObject;
// Convert the date object back to a string in a new format
info dateObject.toString("dd-MM-yyyy hh:mm:ss");
Converting time formats (24 hours to 12 hours)
You may sometimes need to switch between a 24-hour format and a 12-hour format when using zoho.currenttime. Thankfully, Deluge makes this simple. Here’s how you can do it:
currentTime = zoho.currenttime;
info currentTime.toString("dd-MM-YYYY hh:mm:ss a");
// Example output: 25-09-2025 11:11:11 AM
In today's globalized world, your customers may be spread across different time zones, and to add to the complexity, large countries like the USA or Russia have multiple time zones even within their own borders. This can easily lead to head scratching scenarios when working with time-based data. Fortunately, Deluge has got your back here too.
The trick is to first convert the date-time string into a unixEpoch timestamp and then use toDateTimeString() to display it in the target time zone.
Converting your account's time to a user's time zone
The zoho.currenttime variable returns the time based on the setting you've chosen. Let's assume that your account is set for IST (Indian Standard Time) and you want to display it for a user in Los Angeles. Here's how to do it:
// zoho.currenttime returns an IST time
datetimeString = "21-Aug-2025 15:50:13";
// Convert the string to a Unix timestamp
unixValue = datetimeString.unixEpoch();
// Convert the Unix timestamp to a datetime string in the target timezone
info toDateTimeString(unixValue, "dd-MMM-yyyy hh:mm:ss", "America/Los_Angeles");
// Output: 21-Aug-2025 03:20:13
Converting between two specific time zones
What's more, the same approach can also be applied to convert between two time zones. You can specify the source time zone during the Unix conversion to do this. This is particularly useful when your input string is from a known time zone that isn't your server's default.
The below script demonstrates time conversion from IST to Sydney time:
// Specify the source timezone (IST) when converting to Unix epoch
unixValue = "25-Aug-2025 14:28:53".unixEpoch("IST");
// Convert to the target timezone (Australia/Sydney)
info toDateTimeString(unixValue,"dd-MMM-yyyy HH:mm:ss","Australia/Sydney");
// Output: 25-Aug-2025 18:58:53
You can learn more about toTime and toDateTimeString functions at these help links.
We hope these tips help you handle date and time operations in your Deluge scripts more effectively—they can be used across all Zoho services that support Deluge.
Deluge is a vast and powerful language and we aim to help you master it to make your life easier. We'll be back with more tips and tricks soon, so stay tuned!
And if you have any questions or other cool tricks, please share them below!
Until next time,