Checkout UI > Best Practice Get Store Current Date

Hiya,

I need to do some date comparisons within my Checkout Extension, which of course requires getting the current DateTime..

Currently I’m simply doing:

const todaysDate = new Date();

However..

  1. It won’t be in the Stores Datetime
  2. I’ve read multiple sources saying that creating dates this way can have undesirable results

Are there any best practices or alternatives to getting the stores current date? I can’t see anything within the API options, the only other idea I have is to use a Shop Metafield and Flow to keep it up to date each day :person_shrugging:

As for the reason as to why I require the current DateTime, I’m using the DatePicker component but need to be able to block off dates based on a relative factor, i.e. lead days. The relative factor should be against the store, and not the users timezone.

Thanks in advance.

Not sure if there are any patterns for checkout extensions/flows honestly! I’d recommend storing dates in UTC, and comparing against another UTC date.

In your admin (date picker), you could show in the store(s) timezone or the browser timezone (as per your preference), but then always save the date in UTC.

Hope that points you in the right direction - perhaps someone has a more polished example :slight_smile:

@bkspace Thanks for the response, it’s an extension only app (although I’d like to keep it that way) - so I don’t have much control over how the dates are saved in the back-end :pensive_face:

Think I’ll go with the Shop metafield approach for now unless someone suggests a better route