Catalog client script - How to set the time of a Date/Time variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:22 AM
Hi
I'm trying to set the time of a date/time variable in a catalog client script.
However, the date gets changed and set. But the time remains on 00:00:00.
var dateNumber = getDateFromFormat(g_form.getValue('temp1'), g_user_date_format);
var date = new Date(dateNumber);
// Initialize a new Date object
var newDateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate());
// Set the time to 23:59:59
newDateTime.setHours(23);
newDateTime.setMinutes(59);
newDateTime.setSeconds(59);
// Set the value in the datetimeField
g_form.setDisplayValue('temp2', newDateTime);
Temp1 is a date variable and temp2 is a date/time variable.
The script gets the date that is selected in temp1 and puts it in temp2 and should add the time 23:59:59.
However the date is set but the time is not.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:32 AM
Please try to use GlideDateTime instead of Date
var newDateTime = new GlideDateTime(date.getFullYear(), date.getMonth(), date.getDate());
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:35 AM
Hi @KoenHaemels
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:35 AM
Hi @KoenHaemels ,
Use Glide Date time as it is a server side api, so you have to use glideAjax in this case.
May I know your problem statement that you are trying to solve.
If my solution helps you please mark my solution helpful.
Thanks and regards,
Saurabh Dubey.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2024 08:52 AM
Hi @KoenHaemels ,
Just replace Date in your code with GlideDateTime
This will fix the issue & help you populate time as well along with date.
Please mark it as "Accept as Solution" and "Helpful". if this solution helped you.
Thanks & Regards,
Madhan Somesh.