Add current dateTime to function input query #416
Replies: 6 comments 26 replies
-
Getting the exact time is critical to some custom logic and is an absolutely necessary feature. Example: Time the function needs to be active can be set to a half an hour or 45 minutes, due to store special offer campaign. Currently that is not possible to control. |
Beta Was this translation helpful? Give feedback.
-
Is there a reason you can't use input query variables for this? |
Beta Was this translation helpful? Give feedback.
-
+1 on this. Have a need to be able to block checkout if items were added to cart more than X minutes ago. In the majority of cases X will be a short time-frame such as 15-30 minutes. Idea would be to:
|
Beta Was this translation helpful? Give feedback.
-
hey @nickwesselman and team- Running into an issue with localTime. I've removed the variables I was passing in the Input to isolate the problem as much as possible. My super contrived input looks like this: All of the hourN's evaluate to false when the function runs: any thoughts? |
Beta Was this translation helpful? Give feedback.
-
+1 🙏 This would be really useful when you need to compare time with a line-items attribute |
Beta Was this translation helpful? Give feedback.
-
Adding another use case here as I think this is a very important feature that is definitely needed within the community. Products can be placed on a 24 hour hold by customers. A timestamp is added to a product metafield of when that hold expires. If the hold date is lower than the current date, the hold is expired and the checkout/cart should be invalid. This is the current structure of the Cart validation function input using version 2025-1 of the API: query RunInput {
cart {
lines {
merchandise {
... on ProductVariant {
product {
hold_date: metafield(namespace:"hold", key: "date") {
value
}
}
}
}
}
}
shop {
localTime {
date
has_expired_hold_future_date: dateTimeAfter(dateTime: "2025-02-28T12:00:00") # returns false
has_expired_hold_past_date: dateTimeAfter(dateTime: "2025-02-24T12:00:00") # returns true
}
}
} The dateTimeAfter and dateTimeBefore functions won't work for our use case, as these require the DateTime being hardcoded within the function input. We need to be able to use the DateTime stored in the product metafield. Our ideal scenario for this would be if Shopify is able to add the DateTime into the LocalTime Object. That way, we can perform the check within the Function logic. shop {
localTime {
date
dateTime
}
} Outputs {
shop: {
localTime: {
date: "2025-02-25",
dateTime: "2025-02-25T12:00:00"
}
}
} |
Beta Was this translation helpful? Give feedback.
-
#215 shipped date and comparisons, but no dateTime. @nickwesselman mentioned this is due to function run caching.
We need (and others report needing) the current dateTime. Here's our use-case:
specifiedDeliveryDate
.specifiedDeliveryDate
.Actual behavior
There is no
dateTime
, onlydate
, nor do any comparison functions work to compare the current dateTime to a variable. It currently only allows comparison to a metafield value, but we can't update a metafield value to be the 8:00 pm the day before the Cart attribute'sspecifiedDeliveryDate
.To solve my use-case, I did a workaround using a combination of
date
andtimeAfter
but had to hardcode the cutoff time. Eventually, we'll want to have different cutoff times per delivery day and doing a dynamic cutoff of hour granularity would get a bit hairy as you'd have to add 24afterX...
fields.Expected behavior
Shopify adds a
dateTime
field toLocalTime
that can be used in validations in a function run (e.g. compare it against a Cart attribute or Shop metafield that holds a hash like{ "2024-01-04": "2024-01-03T20:00:00", ...}
).Beta Was this translation helpful? Give feedback.
All reactions