How to get date of one day before in extjs field - date

I have the following date field i want to get date of one day before , how can i get that ?
In my form panel
items: [{
fieldLabel: 'Start Date',
name: 'fromdate',
ref: '../fromdate',
id: 'fromdate',
vtype: 'daterange',
value: new Date(),
endDateField: 'todate' // id of the end date field
}, {
fieldLabel: 'End Date',
name: 'todate',
id: 'todate',
vtype: 'daterange',
value: new Date(),
startDateField: 'fromdate' // id of the start date field
}]
Today I am getting 03/23/2011 but I want 03/22/2011 How I can get 03/22/2011?

Speaking ExtJS language, you can use Ext.Date library for manipulation dates. For example:
Ext.Date.add (new Date(),Ext.Date.DAY,1)
Depending on your code logic, you can modify the default value of date field by several ways:
1) In the item's value configuration:
{
...
vtype: 'daterange',
value : Ext.Date.add (new Date(),Ext.Date.DAY,1),
fromDateField: 'fromdate',
...
}
2) During the component's event. Basically, ExtJS containers have initComponent method which is the most first running, but be sure to set your code after callParent() method in order to access items collection. Example:
initComponent: function() {
...
this.callParent(arguments);
this.items.getByKey('fromdate').value = Ext.Date.add (new Date(),Ext.Date.DAY,1);
...
}

Try this:
new Date().add(Date.DAY, -1);

Or this:
var date = new Date();
date.setDate(date.getDate()-1);

Related

How to format json data in miliseconds to Date format in highcharts?

I get array of date from json as 1420185600000,1420531200000,1420617600000,1420704000000,1420790400000,1420876800000. How do I format it to show the correct date in the XAxis labels of the highcharts?
You need to tell highcharts that the xAxis is a date type.
xAxis: {
type: 'datetime'
},
You may need extra formatting if you want the date displayed in some form other than the default. That can be done via the labels.formatter.
Sample code that lets you do what you want (minus what formatting you want your date in):
xAxis: {
categories: [1420185600000,1420531200000,1420617600000,1420704000000,1420790400000,1420876800000],
labels: {
formatter: function () {
return new Date(this.value);
}
}
},
You would then need to determine what parts of your new date string you actually want to show. The sample above doing return Date(this.value) is the kitchen sink approach.
UPDATE: If you want the strings formatted, Highcharts gives you functions to set up the date string. See this fiddle (same as fiddle linked in the comments below with formatter using highcharts): http://jsfiddle.net/CaptainBli/psd3ngsh/13/
xAxis: {
type: "datetime",
categories: xArray,
labels: {
formatter: function () {
return Highcharts.time.dateFormat('%Y-%m-%d %H:%M:%S.%L', new Date(this.value));
}
}
},
arrayOfDatesFromJson = arrayOfDatesFromJson.map(function (element) {
return new Date(element);
});

Formatting a date from an ODataModel in a SAPUI5 table

I have got a SAPUI5 table that is populated from an OData Model. One of its columns is a date/time field that I'd like to format, but I can't figure out how to do it in SUI5.
This is what I'm doing now:
var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Date"}),
template: new sap.ui.commons.TextView().bindProperty("text", "DATE"),
sortProperty: "DATE",
filterProperty: "DATE"
}));
Here's the first couple of lines of output (my browser language is German):
All I want to do is change the date and time format to, say, mm/dd/yyyy hh:mm
I did some searching, and the following question is exactly my problem - but there is an accepted answer that either I do not understand or that does not actually solve the problem:
Date format in a table SAPUI5
I realize this might be a trivial question and I just missed how to do this easily, or it is dealt with in one of the official tutorials. In that case, please just point me to it in the comments and I will delete this question.
Using a formatter function is very flexible, but if you're looking for something simpler without having to write your own format logic, you can consider using the type property rather than the formatter like this:
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "OrderDate",
type: new sap.ui.model.type.Date({pattern: "MM/dd/yyyy hh:mm"})
})
May also be worth considering the standard model formatters: sap.ui.model.type.DateTime and sap.ui.model.type.Date
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "DATE",
type: new sap.ui.model.type.DateTime,
formatOptions: { style: "medium" }
})
XML example (as always use XML ;)
<Text text="{path : 'runDateTime',
type : 'sap.ui.model.type.DateTime',
formatOptions: { style : 'medium'}}" />
Since using UI5 is often a conversation about applying a standard view for an application, using the standard formatting may be a useful idea.
use formatter-function:
var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Date"}),
template: new sap.ui.commons.TextView({
text : {
path : 'DATE',
formatter : function(value){
return /* TODO: some format logic */;
}
}
}),
sortProperty: "DATE",
filterProperty: "DATE"
}));
I am also adding how to format numbers using the formatter function.
<template> = new sap.ui.commons.TextField().bindProperty("<value>",{
path: "<GROSSVALUE>",
type: new sap.ui.model.type.Integer({
maxIntegerDigits: 10,
minFractionDigits: 2,
maxFractionDigits: 2,
groupingEnabled: true,
groupingSeparator: ",",
decimalSeparator: "."
})});

change the date format in a grid field ExtJS

simple question but I can't figure out how to resolve it.
I'm receiving a date with hour from JSON with this format :
"date_deb":"2013\/12\/28 23:00:00"
Note that the \ are for escaping the / and are not displayed.
I would like to display this dates in this format into my grid :
"28/12/2013 23:00:00"
I've tried this into my fields definition:
{name:'date_deb', type: 'date', dateFormat: 'd-m-Y H:i:s'}
But it's not working, nothing is displayed.
By checking the ExtJS docs, I've seen this :
dateReadFormat
I'm using ExtJS4.2
In your field definition provide the dateFormat as it is returned from the server:
{name:'date_deb', type: 'date', dateFormat: 'Y/m/d H:i:s'}
and then in your column config use ExtJS's built-in dateRenderer with the format you'd like to render your dates with:
renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s')
You'll only need dateReadFormat and dateWriteFormat if you have a reader (to read data from server) AND a writer (to send modified data back to server) which need different date formats. Otherwise dateFormat will apply as the default format for both.
If the above doesn't work for you, try adding xtype: 'datecolumn' in your grid's 'columns' config.
columns: [{
text : 'date',
dataIndex: 'LoginDateTime',
xtype: 'datecolumn',
format: 'Y-m-d g:i A',
}]
This should work.
use this function to render date for grid
In your column definition define renderer as this
renderer: renderDate
example { dataIndex: 'TaskEndDate', header: 'PlannedEndDate', flex: 1, renderer: renderDate },
function renderDate(value)
{
if (value == '' || value == undefined) {
return '';
}
else {
getDate = new Date(parseInt(value.substr(6)));
}
return Ext.util.Format.date(getDate, 'm-d-Y');
}
In your column config use "formatter".
formatter: 'date("d/m/Y H:i:s")'

ST datePicker and date issue

Platform is Sencha Touch 2.1.1. I am using a datPicker in a form panel as follows:
{
xtype: 'datepickerfield',
destroyPickerOnHide: true,
name : 'dateOfEvaluation',
label: 'Date of evaluation',
dateFormat: 'm/d/Y',
value: new Date(),
picker: {
yearFrom: 2013
}
},
which is being saved to as a date type in my model:
{name: 'dateOfEvaluation', type: 'date'},
If there is a value in the store it gets rendered via an itemTpl via the follwing method:
onSelectSiteGeneral: function(view, index, target, record, event) {
console.log('Selected a SiteGeneral from the list');
var siteGeneralForm = Ext.Viewport.down('siteGeneralForm');
if(!siteGeneralForm){
siteGeneralForm = Ext.widget('siteGeneralForm');
}
siteGeneralForm.setRecord(record);
siteGeneralForm.showBy(target);
}
This all works fine and dandy.
The problem is with records that do not have dates saved in them. In localStorage for a date type, the null/empty value seems to be 0, which gets displayed on my above form as '12/31/1969.' I know I could write a handler to have this display as the current date, but am sure how to proceed (I cannot use a default value: new Date(), btw, since this does not work with a value already in the data store being rendered to the form). I know I would have to add n-days to zero to get the current date, but am unsure how to get this to rerender in my form.
Any suggestions for how to get the 0th date to show up as a more realistic date, such as the current date (I will stress that default dates do not seem to work when using the above method, onSelectSiteGeneral). Grazie!

jqGrid filterToolbar - filter on DateTime using jquery ui datepicker

I have been looking at filtering jqGrid by datetime using the filterToolbar.
My question is based on Olegs excellent answer here.
I finally figured out how to trigger toolbar search on date as follows:
colModel: [{
name: 'RequestDate',
index: 'RequestDate',
formatter: 'date',
formatoptions: {
newformat: 'm/d/Y h:iA'
},
searchoptions: {
sopt: ['eq'],
dataInit: function (elem) {
$(elem).datepicker({
changeYear: true,
changeMonth: true,
onSelect: function (dateText, inst) {
setTimeout(function () {
$('#MyGrid')[0].triggerToolbar();
}, 50);
}
});
}
}
}]
Now when selecting the date from the picker I want to return all records for the given date ignoring the time.
I have tried updating the FilterObjectSet method with no luck. Has anyone been able to implement this successfully?
What I've tried: (see the code in Olegs linked solution)
Setting the FormatMapping to "(dateadd(dd,0, datediff(dd,0, it.{0})) = #p{1})" and
addingSystem.DateTime to the switch statement:
case "System.DateTime":
param = new ObjectParameter("p" + iParam, Convert.ToDateTime(rule.data));
break;
But this will result in a EntitySqlException:
'dateadd' cannot be resolved into a valid type or function.
Does anyone have a solution?
Ok figured it out this morning:
Added a new Operation:
de //de - date equals
Added a new string to FormatMapping that uses SqlServer.datediff:
"(SqlServer.datediff('DAY', it.{0} , #p{1}) = 0)" //de - date equals
and added the date case:
case "System.DateTime":
param = new ObjectParameter("p" + iParam, Convert.ToDateTime(rule.data));
break;
Changed sopt in colModel to sopt: ['de']