I need help with Get
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 05:40 AM
// 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');
};
// Pegando o início e o fim do dia atual (meia-noite até 23:59:59)
const inicioDia = startOfDay(new Date()); // Meia-noite de hoje
const fimDia = endOfDay(new Date()); // 23:59:59 de hoje
console.log(inicioDia,fimDia)
// Formate as datas
const startDia = formatDate(inicioDia); // Meia-noite de hoje
const endDia = formatDate(fimDia); // 23:59:59 de hoje
// Crie a query combinada (busca por `opened_at` ou `sys_updated_on` no dia de hoje)
const betweenOpenedAt = `opened_atBETWEEN${startDia}@${endDia}`;
const betweenUpdatedAt = `sys_updated_onBETWEEN${startDia}@${endDia}`;
const betweenCloseAT = `closed_atBETWEEN${startDia}@${endDia}`
// Comando que combina as duas condições com OR
//const dateQuery = `${betweenOpenedAt}^OR${betweenUpdatedAt}^OR${betweenCloseAT}`;
const dateQuery = `${betweenOpenedAt}`;
console.log(dateQuery)
I'm creating a URL to retrieve data from the Incident table, and I want everything that was created, updated or closed on the current day (today). The date format I'm returning is this:
opened_atBETWEEN2024-10-01 00:00:00@2024-10-01 23:59:59
But for some reason I'm retrieving data from yesterday too, and I only want today's data. Can anyone help me? My URL is like this:
export const urlIncident = `${baseUrlIncident}?sysparm_query=${dateQuery}^${orderby}&${limit}`;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 05:50 AM
The timezone of your executed query will be based on the user's timezone of the account you're using to authenticate with ServiceNow. Possibly this user record is in a different timezone to the instance and therefore the query is extending into a bigger window than you realise?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 05:53 AM
It is possible, and maybe that is it, but what I want to know is, is my BETWEEN field correct? In terms of date/time? Because if this format is not correct I need to know how to solve it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 05:58 AM
Yes your format is correct
Example:
opened_atBETWEENjavascript:gs.beginningOfToday()@javascript:gs.endOfToday()
Translates to:
opened_atBETWEEN2024-09-30 23:00:00@2024-10-01 22:59:59
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 06:10 AM
Dude, if my date/time format is correct, what can I do to try to get the data based on the correct result, to get only what was done today based on my time? I don't know what the time zone is of the instance from where I'm getting the GET from. I didn't create the instance, it's from my work.