How I clear the unusable sting on the time in MSSQL?

When I insert time (13:21) as a “time” in MSSQL Server it correctly instert into data base as a 13:21:56.1900000 but when I retrieve time using react it shown with 1970-01-01T13:21:56.190Z like wise. But I only want the time as what I input using the forum. (HH:MM:SS). So, Can I know how to remove those characters which place on front and back?

Screenshot 2022-08-29 095728

This is the table which I retrieve data from my data base.

this is how data shown in database (MSSQL Server)

const date = new Date('1970-01-01T13:21:56.190Z');
console.log(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`);

This should get you started.

I used this but as a output it gave a different time.

Input → (‘1970-01-01T13:21:56.190Z’)
Output ->18:51:56

@RandellDawson How to fix this issue?

Another approach is to split the string using T as the delimiter to get the following array:

['1970-01-01', '13:21:56.190Z']

The take the second element of this array and split it using . as the delimiter to get the following array:

['13:21:56', '190Z']

Then, the first element of this array is your time.

The other way should have worked if your local timezone was the same as the timezone of the MSSQL server.

That being said, you might try the following so the timezone difference would not matter:

const date = new Date('1970-01-01T13:21:56Z');
console.log(`${date.getUTCHours()}:${date.getUTCMinutes()}:${date.getUTCSeconds()}`);
1 Like