Format Correct Between

Arthur Sanchez
Giga Guru

Guys, please help me, what is the correct format to use between in a get request to get time intervals?

 

 

 

// const startDate = '2024-09-11 00:00:00';
// const endDate = '2024-09-12 23:59:59';
// const between = `opened_atBETWEEN${startDate}@${endDate}`

 

 

 

I want to make a get request to get a specific time interval but this way it is not bringing all the data, so I don't know if there is something missing in the format, please help me.

I'm creating a function to automatically get yesterday's and today's data, but I don't know if the format is correct:

 

import { subDays, startOfDay, endOfDay, format } from 'date-fns';

// Pega a data de ontem e formata para começar à meia-noite
const yesterdayStart = startOfDay(subDays(new Date(), 1));
const todayEnd = endOfDay(new Date()); // Data de hoje até as 23:59:59
// Função para formatar a data no padrão que a API espera (YYYY-MM-DD HH:MM:SS)
const formatDate = (date: Date): string => {
  return format(date, 'yyyy-MM-dd HH:mm:ss');
};
// Define as variáveis de data
const startDate = formatDate(yesterdayStart);  // Meia-noite de ontem
const endDate = formatDate(todayEnd);          // 23:59:59 de hoje

// Comando BETWEEN para filtrar entre as duas datas
const between = `opened_atBETWEEN${startDate}@${endDate}`;

 

 

0 REPLIES 0