Skip to content

Date, Day and Time Convention

Abel Mathew edited this page Feb 4, 2021 · 3 revisions

Our project is using date, time and day in multiple places. To maintain uniformity on the back-end and later understanding, we are following the below conventions.

Sample String: 2019-08-05T02:50:49.637Z

When date and time both are to stored

  • Store in the database as DateTime type. The timezone by default is UTC, and we store in that.
  • Timezone if needed can either be processed on API code or on client-side as per the case.

When only time is to be stored

  • Store in the database as DateTime type. The date part will be any random date.
  • Discard the date information from the data while processing on client-side preferably.
  • Timezone if needed can either be processed on API code or on client-side as per the case.

When the day is to be stored

  • Use the following convention for schema
{
  day:{
   type: Number,
   max: 6,
   min: 0,
  }
}
  • In the database, it will be day: Number

Example
day: 1
This would mean the day is Monday

0 corresponds to Sunday and 6 to Saturday.

NOTE : Storing in UTC timezone may require time conversion, check the case and do it to make sure data is stored in UTC timezone