Bulk Convert Spreadsheet Dates to Date-Time Objects (No Loops Required!)
Have you ever pulled data from Google Sheets using the List Rows action, only to realize your date columns are being treated as plain text strings?
When this happens, you can't easily filter or query those dates chronologically. The typical solution is to use the Convert to Date/Time action. However, if you have dozens or hundreds of spreadsheet rows, putting that action inside a "For Each" loop just to convert them one by one makes your flow unnecessarily messy and slow.
Today, we're going to show you a "smart trick" to bulk-convert all your spreadsheet dates at once using the Convert JSON to Object action!
Step 1: Get a Sample of Your Data
Before we can convert your data, Zenphi needs to know exactly what your spreadsheet rows look like. We'll do this by running a quick test.
Add a Log to History action right after your Google Sheets List Rows step.
Map the "Rows" collection (your spreadsheet data output) into the Log to History action.
Run a test of your flow.
Check your flow history and copy the output. It will look something like this sample.
Sample Output:
[
{
"rowNumber": 2,
"Name": "John Doe",
"DateOfBirth": "10/15/1990",
"Department": "Sales"
},
{
"rowNumber": 3,
"Name": "Jane Smith",
"DateOfBirth": "05/22/1985",
"Department": "Marketing"
}
](Note: In this example, "DateOfBirth" is the column holding our dates).
Step 2: Add the "Convert JSON to Object" Action
Now that you have your sample data copied, let's set up the bulk conversion.
Drag and drop the Convert JSON to Object action into your flow.
In the input field, map your entire collection of spreadsheet rows from the List Rows action.
Click on the Schema option.
Paste the sample data you copied in Step 1 into the "Sample JSON Payload" box.
Click the Infer from sample button.
Zenphi will automatically generate a schema (a structural map of your data) that looks like this:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"rowNumber": {
"type": "integer",
"title": "Row Number"
},
"Name": {
"type": "string",
"title": "Name"
},
"DateOfBirth": {
"type": "string",
"title": "Date Of Birth"
},
"Department": {
"type": "string",
"title": "Department"
}
}
},
"$schema": "http://json-schema.org/draft-04/schema"
}Step 3: The Magic Trick (Customize the Schema)
By default, Zenphi still thinks the "DateOfBirth" column is a regular text "string". We are going to manually force Zenphi to read it as a date.
Find your date column in the schema code. Add one extra line of text right below "type": "string", that says:
"format": "date-time",Before:
"DateOfBirth": {
"type": "string",
"title": "Date Of Birth"
}After:
"DateOfBirth": {
"type": "string",
"format": "date-time",
"title": "Date Of Birth"
}The Result!
Save your action! By simply adding that one line to the schema, Zenphi will now process your entire spreadsheet collection and instantly convert every single text date in that column into a usable Date-Time object.
You can now pass this converted collection straight into a Query Collection step to easily filter your dates (like finding all dates from last week), no messy loops required!