The Dev Pages

A knowledge base for web applications development (and beyond)

Archive for the ‘Elixir and Phoenix’ Category




Issue: Getting the (current or otherwise) date for a specific timezone can be involve some trickiness.

Example: I need to know the current date in New York, even though I reside in Austin, TX. It is 12/11/2020 11:39 PM CT, so I want to ensure the date on the display for NY data shows 12/12/2020.

Example: The date of a transaction is stored as a UTC timestamp with the time as midnight (instead of using a time-agnostic date column, outside of one’s control). I need to determine, when saving the transaction, what the current date should be stored as, based on NY time.

One solution:

NOTE: When dealing with DateTimes to save to a database, leaving the microseconds on can cause issues. I’m surprised the DateTime result doesn’t default to the more compatible format (TBD on whether from Elixir or Timex). See https://github.com/riverrun/phauxth-example/issues/10