Skip to content

Instantly share code, notes, and snippets.

@srph
Created June 7, 2019 03:24
Show Gist options
  • Save srph/a223c774990a02eca5025ca81b27dd2e to your computer and use it in GitHub Desktop.
Save srph/a223c774990a02eca5025ca81b27dd2e to your computer and use it in GitHub Desktop.
JS: mysql-formatted string with date-fns
import { format } from 'date-fns'
/**
* Gives you a mysql standard formatted datetime
* e.g., 2018-08-08 23:00:00
*/
function getStandardFormattedDateTime(date: Date = new Date()) {
return format(date, 'YYYY-MM-DD HH-mm-ss')
}
export default getStandardFormattedDateTime
@kkomelin
Copy link

kkomelin commented May 8, 2023

Thanks

@hcz
Copy link

hcz commented Oct 4, 2023

// v2.16.1
format(new Date(), 'yyyy-MM-dd HH-mm-ss')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment