@leafygreen-ui/date-utils
Version:
LeafyGreen UI Kit Date Utils
15 lines (12 loc) • 404 B
text/typescript
import { isValidDate } from '../isValidDate';
import { DateType } from '../types';
/**
* Returns only the Date portion of the ISOString for a given date
* i.e. 2023-11-01T00:00:00.000Z => 2023-11-01
*/
export const getISODate = (date: DateType): string => {
if (!isValidDate(date)) return '';
const isoString = date.toISOString();
const isoDate = isoString.split('T')[0];
return isoDate;
};