Date display Appery.io - date

I use a date picker that saves the date in a yyyy-mm-dd format in a database. It then automatically adds time that always appears as 00:00:00. So for example it displays the date like this : 2014-12-14 00:00:00. I want it to display just the date in a mm-dd-yyyy format.
I use the code below but something seems to be wrong with it because it simply doesn't change the way it is displayed. I want to split up each of the values, then display only the date in a different format.
var parts = value.split("/");
return parts[1] + "-" +parts[2] + "-" +parts[0];
What can I do to make it work? Javascript please.
Thanks in advance.

It's a wide variety of solutions. Depends on you server-side settings too, but I will assume, that you use common for most websites MySQL DB and PHP.
You can change you column type to DATE. As said in docs:
The DATE type is used for values with a date part but no time part.
MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The
supported range is '1000-01-01' to '9999-12-31'.
You can change your column type to VARCHAR and store a date in any format you like when INSERT it
You can convert it to proper format using MySQL built-in DATE_FORMAT()
SELECT DATE_FORMAT('2014-12-14 00:00:00', '%c-%e-%Y');
will give you 12-14-2014. Here is sqlfiddle,
just change first param to your column name in query
On server you can use PHP's date() function like this
$yourdate = '2014-12-14 00:00:00';
echo date("m-d-Y", strtotime($yourdate));
Closer to your question, how to do it in JS? It also has special object for this: Date(). Put your date in constructor, then use methods:
var yourdate = new Date('2014-12-14 00:00:00');
alert(yourdate.getMonth() + "-" + yourdate.getDate() + "-" + yourdate.getFullYear());
JSFiddle < - here
So, as far as almost every platform understands this datetime format - you can use any tool for converting it

Related

Error on converting String to Date

My date data looks like this: 20151112,20151116 .I want to convert it into Date "MM/DD/YYYY", then i used the Code:
=CDATE(MID(Fields!Date.Value,5,2)&"/"&(RIGHT(Fields!Date.Value,2)&"/"&LEFT(Fields!Date.Value,4)))
But there is an Error: Conversion from String 11/24/2015 to type Date is invalid. Can you please help me how to fix this Problem?
You are making your life harder than it needs to be by converting your string date into a potentially ambiguous localised date format (MM/dd/yyyy) and then trying to actually convert it to a date datatype. If you go about this the other way around - converting your data to a date data type and then formatting it - you will avoid a lot of headaches.
To do this, you need to first add in some forward slashes / to your string dates, retaining the yyyy/MM/dd:
=CDate(left("20160131",4) & "/" & mid("20160131",5,2) & "/" & right("20160131",2))
Now that you have a date data type that will always be properly handled by SSRS, you can format it however you require for being displayed in your application:
=format(CDate(left("20160131",4) & "/" & mid("20160131",5,2) & "/" & right("20160131",2)),"MM/dd/yyyy")

wrong date when i change int time with FROM_UNIXTIME

I have a old database that i want to transfer, but i have some trouble with my column dateP(int). I got a wrong datetime.
In my old script, I enter the date-time like this:
$date_created = time();
$data_insert = "INSERT TO table $date_created, $title";
Now I have the column datePub (int) that I convert to time stamp format,
For resolve this problem i make this.
UPDATE `table ` SET `date_created` = FROM_UNIXTIME(`datePub `)
But I got a wrong date when I make this date('M d, Y', $PuDate);
I put the right specifier in date_format and its good now.

How can I add several months to a date coming from a date form field?

With DateJS, you'd add e.g. six months to the current date like this:
Date.today().addMonths(6);
However, I need to add 24 months not to today's date, but to a date which a user has typed into a date field. So the today() should in principle be replaced by something like this.getField('begin_date').value.
The result shall be written into another data form field.
I tried hard, but couldn't make it. Can anyone help me out?
Providing the input value is a textual representation of a date, you need to convert it into a Date object at the first place. Then you can work with it as you want.
DateJS has a pretty smart parse() function which does exactly that, so you'd achieve it like this:
Date.parse(this.getField('begin_date').value).addMonths(24)
When a specific date format is needed, like DD.MM.YYYY commonly used in Europe, you can use parseExact() and specify the format. Like this:
Date.parseExact(dateToParse, 'dd.MM.yyyy') // leading zeroes required; parses 01.04.2014 but not 1.4.2014
Date.parseExact(dateToParse, 'd.M.yyyy') // leading zeroes not required; parses both 01.04.2014 and 1.4.2014
Here is a solution that I found for my problem, using DateJS as well:
start = this.getField('begin_date').value;
var d1 = util.scand("dd.mm.yyyy", start);
var myDate = new Date(d1);
result = myDate.addMonths(24);
This works pretty fine, also spanning leap years, except for the 28th of February, 2014/2018/2022 ... ; the result then will be the 28th of February, 2016/2020/2024 ... and not the 29th of February 2016/2020/2024... In these cases it's up to the user to accept the 28th or to manually change the date to the 29th.

exhibit timeline date format

I have an exhibit timeline, my data is in format "2013-12-15T07:39:19.000-04:00" and I'd like to control how the date is displayed. Right now, it displays only day and month by default but I'd like it to display year as well.
My guess is exhibit using .js code?
If you want to format date to string the way you want,
Javascript can be tricky and you might have to parse on your own.
Something like this:
d = new Date("2013-12-15T07:39:19.000-04:00")
date_str = d.getDate() +"-" + d.getMonth() + "-" + d.getFullYear()
alert(date_str) //result depends on local computer timezone
Consider adding js library specific for date formatting, like momment.js (I have not tried it though)

Why does ExtJS subtract a day when formatting a date?

Using ExtJS 4.0.2, I can type the following into the console:
Ext.util.Format.date('2012-01-13', "m-d-Y");
I get 01-12-2012
Why?
I can correct it with:
Ext.util.Format.date('2012-01-13 00:00:00', "m-d-Y");
Ext.util.Format.date in Ext 4.0.2 uses a Date object or a String (your case). This string is parsed using the native Date.parse() using the UTC time zone.
Try to explicitly parse it using Ext.Date.parse:
var dt = Ext.Date.parse("2012-01-13", "Y-m-d");
Ext.util.Format.date(dt, "m-d-Y");
This problem exists in Ext3, but the solution is slightly different:
var dt = '2012-01-31'; //date string
dt = Date.parseDate(dt, "Y-m-d");
Ext.util.Format.date(dt, 'm/d/Y'); //returns 01/31/2012
If you're unable to use Gregor's answer (e.g. filling a grid), note that changing the input to a non ISO 8601 date format will avoid the UTC parsing as well. For example
Ext.util.Format.date('01/13/2012', "Y-m-d");
will give 2012-01-13