Skip to content

Instantly share code, notes, and snippets.

@mkanenobu
Last active August 23, 2023 03:48
Show Gist options
  • Save mkanenobu/f3b0f766f6648b131cc387a68cb7320d to your computer and use it in GitHub Desktop.
Save mkanenobu/f3b0f766f6648b131cc387a68cb7320d to your computer and use it in GitHub Desktop.
export const datetimeWithTZ = <T extends ColumnBaseConfig>(
column: MySqlDateTimeString<T>
) =>
sql`DATE_FORMAT(${column}, '%Y-%m-%dT%TZ')`.mapWith((v) => new Date(v));
// example
// await db.select({ createdAt: datetimeWithTz(table.createdAt) }).from(table);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment