- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 10:53 AM - edited 11-03-2023 11:53 AM
Can anyone explain how to use datetime in from this 2023-11-03 22:51:34 to this 20231103-225134.formate on onchange client script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:48 PM
Hello @Ajay Singh2
It seems you have already brought the datetime
Just use the below code :-
var gdt = g_user_date_time_format;
var dateTime = gdt.split(' ');
var date=dateTime[0].split('-');
var time=dateTime[1].split(':');
var res1= date[0]+date[1]+date[2];
var res2= time[0]+time[1]+time[2];
var res=res1 +'-' +res2;
alert(res);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 02:34 PM
@Ajay Singh2Nah, if you would be using my code, you would have the date formatted as desired in there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:15 PM - edited 11-03-2023 01:17 PM
Could you explain the business need?
System date on client side sounds confusing and the need to format a date specifically also is not something normally done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:30 PM
I guess the safest option is to do what @Samaksh Wani suggested: get the date from server side, using GlideAjax.
While you could get the current date purely on client side, e.g:
alert(getNowDateTime());
function getNowDateTime () {
var dateOut = new Date();
return formatDate(dateOut, 'yyyyMMdd-HHmmss');
}
it can be that the current user's current device doesn't have the correct date/time or time zone and could lead to wrong results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:41 PM
can you provide code to use in script include and client script for this. Currently i am getting date with this script. See below screenshot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2023 01:48 PM
Hello @Ajay Singh2
It seems you have already brought the datetime
Just use the below code :-
var gdt = g_user_date_time_format;
var dateTime = gdt.split(' ');
var date=dateTime[0].split('-');
var time=dateTime[1].split(':');
var res1= date[0]+date[1]+date[2];
var res2= time[0]+time[1]+time[2];
var res=res1 +'-' +res2;
alert(res);