How can I take start of currentdate

I want to display only currentdate’s data.
And i want to compare it against a field which is a timestamp.
So i need to take start of current date i.e current date at 00:00:00 hrs sec
For eg. if current date is 15 Nov 2024. I want the output to be -
2024-11-15 00:00:00

I can’t use timestamp below code here, as it will give current timestamp.
I need the timestamp from the start of the date. (2024-11-15 00:00:00 )

I have this code:
const moment = require(‘moment’);
const today = moment();
var todayDate = today.format(‘YYYYMMDD’);
let todayDate = moment(todayDate).unix();
pm.globals.set(“todayDate”, todayDate);

This gives me current timestamp.
Can somebody help me here

The following appears to work.

let c = new Date(); // take the current date/time

c.setHours(0);
c.setMinutes(0);
c.setSeconds(0);

const moment = require("moment");

var todayDate = moment(c).format("YYYY-MM-DD HH:mm:ss");

console.log(todayDate); // "2024-11-15 00:00:00"

This does the job.
Thank you very much.

Another question.
I was writing a python code to call this api.

I haven’t written a python code with such pre-request script before.
Can you help me how do we pass this code as a value in python code?
What are the libraries used?

Also,
let c = new Date()
gives local time. Is there a way to input the GMT time in this statement.

let c = new Date().utc(); → This doesn’t work.

Sorry, i am new to this

Postman uses JavaScript under the hood, and moment is a Node.JS JavaScript library.

You will have to find something similar for Python.

let c = new Date().toISOString();

javascript - How to convert a Date to UTC? - Stack Overflow

I thought this will work but I would like to refrain my question.

I want to list down only last day’s data(Date to be in UTC).

If now in UTC is 18 Nov 11 AM.
I should get the date as: 2024 11 17 00:00:00

By using your method, i am getting my local time which when converted to UTC is giving another date and time.

I want last date’s time and date in UTC.
Thank you for your help.

const moment = require(‘moment’);

//let c = moment().subtract(1, ‘days’); // take the current date/time

let c = new Date();

console.log(c);

c.setDate(c.getDate()-1);

c.setHours(0);

c.setMinutes(0);

c.setSeconds(0);

console.log(c);

const d= c.toISOString();

console.log(d);
All these values are coming in IST.
I want these values in UTC/PST.
Can you please help.

The problem is determining the timezone difference.

Therefore I would suggest using the moment timezone functionality.

You can import this into the Sandbox using the following code in a pre-request script.

if (!pm.globals.has("moment_js") || !pm.globals.has("moment_tz")) {
    pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.45/moment-timezone-with-data-10-year-range.js", (mtzErr, mtzRes) => {
        pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.30.1/moment.min.js", (mjsErr, mjsRes) => {
            pm.globals.set("moment_js", mjsRes.text());
            pm.globals.set("moment_tz", mtzRes.text());
        })
    })
}

(new Function(pm.globals.get("moment_js")))();
(new Function(pm.globals.get("moment_tz")))();

Moment Timezone | Docs

All you need to work out is the date.

Something like…

let c = moment("2024-11-24T22:00:00Z");

let london = moment.tz(c, "Europe/London").format("YYYY-MM-DD HH:mm:ss"); 
let asiaCalcutta = moment.tz(c, "Asia/Calcutta").format("YYYY-MM-DD HH:mm:ss"); 

console.log(`Asia/Calcultta: ${asiaCalcutta}`); // 2024-11-25 03:30:00
console.log(`London: ${london}`); // 2024-11-24 22:00:00

As soon as you format the date into a string, the setHours and setMinutes methods that are available on a date object are no longer available to you.

If you want to zero the hours, minutes and seconds, you can simply do this in the formatting.

let londonV2 = moment.tz(c, "Europe/London").format("YYYY-MM-DD 00:00:00"); 
console.log(londonV2); // 2024-11-24 00:00:00