Datatable timestamp wrong format - javascript

2019-11-19 15:35:52.494
This is actual data in my database table, but in the datatable I get this:
2019-11-19T10:05
The date format is wrong.
How can i solve this?

The date format is wrong.
The format is not wrong, The T is just a standard (ISO 8601) way to de-limit the time.
To remove T from your datetime string you could format your string using pure Javascript something like this or you can use any other library like moment. Take a look here for formatting using moment js.

In columnDefs, add your target column
$(document).ready( function () {
var table = $('#example').DataTable({
columnDefs:[{targets:4, render:function(data){
return moment(data).format('MMMM Do YYYY');
}}]
});
});
In targets put your column number and In format put the format you want to display. You can try with different format follow this below link
click here for demo

If you don't necessarily need it to be a date type, you could try to cast the timestamp to text in your select statement when you retrieve it from the database, like this:
SELECT TO_CHAR(NOW(),'dd/MM/YYYY hh:mm:ss') AS date_time
Here is more info about formatting using TO_CHAR.

Related

is there a way i can group data by "Month" on tabulator js while having a full date?

I'm using tabulator js library. I know there is a group option where i can group through certain fields i have in my data. I have a field date of the format MM/DD/YYYY. I want to group the data in the table by month only not the full date. How can i achieve that? I have tried splitting the string date from my date on '/' and then taking the first part of it as the month. An error on .split('/') appeared plus if it were to work, I did not know how to continue from there. Any ideas of how to achieve this?
You will need moment.js and then you can do something like:
groupBy: function(data){
return moment(data.dob, "MM/DD/YYYY").startOf("month").format("MMM-YYYY");}
Where you specify the input data format("MM/DD/YYYY"), then normalize those dates to the start of the month(startOf("month") and then return as abbreviated month name with year(format("MMM-YYYY")). You could change ```.format("MMM-YYYY") to what suits.
For demo see fiddle

Jqgrid Date sorting issue with day name and date column

In my Jqgrid table I have a column which has dayName, Date as value,
like, Wed, 01-03-217,
But when I add complete data having days as Tue or Thu, jqgrid shows undefined, NaN-NaN-NaN as column values for both days,
I am using Jqgrid versoin 4.6.0
I have also prepare demo at fiddle. http://jsfiddle.net/alpeshjikadra/jss5b43j/1/
Let me know if anyone knows how to solve this
Thanks
The usage of localized format as the input data (texts like "Thu") in the date is bad practice in general. It's better to change the format of data to use ISO 8601 date format. I mean to post the date "Thu, 09-03-2017" like "2017-03-09".
If you really can't change the format of input data, I could suggest you the following workaround: you can include the line
$.jgrid.formatter.date.parseRe = /[,\s\-]/;
in your code. The parseRe be used internally for parsing the dates. The input format which you use, for example, "Thu, 09-03-2017" contains -, spaces and , as separators between the parts of the date. The regex /[,\s\-]/ corresponds the format.
Resulting demo will be http://jsfiddle.net/OlegKi/jss5b43j/6/
I think there's something with the formatting.
Try removing the ',' from your invdate property strings in mydata eg.: {id:"1", invdate:"Wed 01-03-2017"}
It works for some reason.

EXTJS Ext.util.Format.date Automatic date conversion

I have a date field which contains data coming in from the database as 2015/07/31 13:01:53.180z.
Datetime is stored in UTC on database.
My code looks like this:
var startDateTime = Ext.util.Format.date(StartDateTime, 'm/d/y g:i:s A');
But the output I get is the conversion of UTC to IST(Indian).I checked on Chrome,Mozilla and IE.
I got same output all the time
Does ExtJs does this? Because I haven't wrriten any method for conversion.
I use ExtJs 4.1.1
I would appreciate any help on this.
Timezone is appended in the string->JS Date conversion.
To parse the date from database without timezone conversion you should use the Ext.Date.parse explicitly, not automatically through model field type 'date' or simply JS constructor new Date().
For example:
var db_date = '2015/07/31 13:01:53.180z',
js_date = Ext.Date.parse(db_date.substring(0,db_date.length-5), 'Y/m/d H:i:s'),
date_to_show = Ext.util.Format.date(js_date, 'm/d/y g:i:s A');
Obviously "substring" must be replaced by something better, for example you could format db date (cutting timezone part) in the web service serialization.
If you achieve to clean the date string in the web service you can also add "dateFormat" attribute to model fields to parse date correctly into models.

Display C# DateTime in HTML Text Input

So I'm pulling a DateTime from a database and I want to display it in an HTML text input (<input type="text">).
By the time the C# DateTime is sent to Javascript, it looks something like this: fooDate: {6/22/2011 2:30:00 PM}. But when it is displayed in the <input>, it ends up looking like this: 2011-06-22T14:30:00.
It's kind of annoying because I only care about displaying the date. Why is this this conversion happening, and is there a way to just get it to display the 6/22/2011 2:30:00 PM bit? Can this be accomplished without the use of regular expressions?
Mix and match whatever combination you want to. World is your oyster.
DateTime.Now.Day
DateTime.Now.Month
DateTime.Now.Year
are you able to convert it to string before you pass it to your JS-Method?
string Output = string.Format("{0:G}",DatabaseValue);
Examples for just getting at the date...
DateTime.Now.ToShortDateString();
will return "02/12/2014"
Or you can specify the format you want
DateTime.Now.ToString("yyyy-MM-dd");
will return "2014-12-02"
Try using the String.Format function:
//Here you pull the DateTime from your db
//I show you an example with the current DateTime
DateTime myDateTime = DateTime.Now;
string date = String.Format("{0:dd-MM-yyyy}", myDateTime); //eg: 02-12-2014
//Place the string in your textbox
this.txtYourTextbox.Text = date;
if you don't know which format to use, refer to following article:
String Format for DateTime [C#]

How to change the date format in JavaScript?

I am using one jquery date picker,
with using picker i am getting date in like this format
Friday, May 21, 2010
Now i want to add one day in this date so i think, i can only do if i change the date in exact format like
21/5/2010
I want to only convert that bcz i want to add one day to the particular date.
So what do u suggest me? How can I do that?
Can i do without converting it ?
thanks in advance....
Take a look at http://docs.jquery.com/UI/Datepicker#option-dateFormat
datejs may be useful to you.
In addition to the formatting options given by others, you should add using date objects rather than to the string representation of the date object.
I.E.
// add 5 days to today
var myDate=new Date();
myDate.setDate(myDate.getDate()+5);
I think you need to detail what jQuery plugin do you use.
Is it this one? http://jqueryui.com/demos/datepicker/
If so, then when you cann getDate method, you'll get Date object representing a date. You can easily manipulate it.
The date format has nothing to do with how dates are stored; it only affects the way dates are displayed. JavaScript has a native Date object and jQuery UI's Datepicker allows to access such object:
http://jqueryui.com/demos/datepicker/#method-getDate
Once you have a Date object, you can alter it to suit your needs:
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date
Finally, you can feed it back into Datepicker:
http://jqueryui.com/demos/datepicker/#method-setDate

Categories

Resources