Denton Posted September 22, 2022 Share Posted September 22, 2022 Hi, I am trying to separate date and time of a record in javascript and display it in grid. Like this: In UniDBGrid1 > ClientEvents > ExtEvents > reconfigure i did this: function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) { columns.forEach(function(col,index,cols){ if (col.text === "Sched Date") { col.renderer = function(value,metaData,record){ /* start_date and end_date are both date time. */ var from = record.get(1);// start_date var to = record.get(2);// end_date return '<span>Sep 22 2022</span><br/>' + '<span style="font-size: 9px;color: #808080">09:00am - 01:00pm</span>'; }; } }); } How can i achieve the screenshot above? (or just separate date and time) Thanks, Regards Quote Link to comment Share on other sites More sharing options...
Ron Posted September 22, 2022 Share Posted September 22, 2022 Use JS date functions, i.e. to get hour number use from.getHours() https://www.w3schools.com/jsref/jsref_obj_date.asp Quote Link to comment Share on other sites More sharing options...
Norm Posted September 23, 2022 Share Posted September 23, 2022 Here is a sample javaScript function you can play with to achieve what you want. I created this quickly so am => pm conversion might need adjusting: const dateToString = function (d){ const toTwoDigits = function (d){ d = d.toString() if(d.length < 2){ d = '0' + d; } return d; } const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] let day = d.getDate(); let month = d.getMonth(); let yr = d.getFullYear(); let returnDate = months[month]+' '+toTwoDigits(day)+' '+yr; let hrs = d.getHours(); let mins = d.getMinutes(); let ampm = 'am'; if(hrs > 12){ hrs -= 12; ampm = 'pm'; } let returnTime = toTwoDigits(hrs)+':'+mins+ampm; return returnDate + ' - '+ returnTime; } You can test by pasting in Chrome console followed by: let today = new Date() console.log(dateToString(today)) Quote Link to comment Share on other sites More sharing options...
Sherzod Posted September 23, 2022 Share Posted September 23, 2022 16 hours ago, Denton said: How can i achieve the screenshot above? Hello, If I understand you correctly, you can also use: https://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TField.GetText 1 Quote Link to comment Share on other sites More sharing options...
Denton Posted September 23, 2022 Author Share Posted September 23, 2022 3 hours ago, Sherzod said: Hello, If I understand you correctly, you can also use: https://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TField.GetText Hi, Thanks for the suggestion. I ended up using calculated field to achieve it. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.