Error on converting String to Date - 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")

Related

Unable to filter after Date in Realm swift

I'm trying to apply a filter on realm which includes a Date but with no luck.
I've found out that Date object cannot be passed because the %# format expects a Foundation object as argument, so I've applied a cast to NSDate.
let newDate = Date()
realm.objects(E.self)
.filter(String(format: "%# <= %#", key, newDate as NSDate)).first
The issue that appears is "Unable to parse the format string timestamp==2020-03-20 08:21:00 +0000"
key is the name of the field, which in this case it is "timestamp" and on the model it has the type Date.
Any input is appreciated.
Thanks
You should use:
.filter("\(key) <= %#", newDate as NSDate)
This is calling the overload of Realm's filter method that accepts a format and arguments.
String(format:) is not the right thing to use here, as that just does general string formatting. But here, you want the date to be formatted according to the rules of NSPredicate formats. On the other hand, the key can just be interpolated into the string because the name of the table column doesn't need a special format.
If key comes from a UITextField or something like that, then you might need to beware of injection attacks as well, and validate and/or escape the key properly beforehand.

How to use Thymeleaf and/or spring expression language to convert a string e.g. "2018-02-21" into a date format dd/mm/yyyy (e.g. "21/02/2018")

I am creating a template that needs to format a string variable that is in format yyyy-MM-dd as a date in format dd/MM/yyyy. I have successfully managed this with the below however this doesn't feel right...
<p th:text="${testDate != '' ? #dates.format(#strings.replace(testDate,'-','/'),'dd/MM/yyyy') : ''}"></p>
Also as additional problem sometimes the date field can come across as a time e.g. "09:03:21" but I can worry about that later.
The date string is retrieved from a service and the format cannot be changed.
Thanks for any help
Try this
<p th:text="${testDate != '' ? #temporals.format(testDate,'dd/MM/yyyy'): ''}"></p>
Check here for better understanding!

Get a DateTime with an specific pattern with nscala-time

I am trying to get this pattern 'dd-MM-yyyy' with a variable of type DateTime
#{DateTimeFormat.forPattern("dd-MM-YYYY").parseDateTime(user.birthday.toString)}
But I am getting this error
java.lang.IllegalArgumentException: Invalid format: "2015-12-10T00:00:00.000Z" is malformed at "15-12-10T00:00:00.000Z"
Is there a way to do this with nscala-time?
makes a difference if I am using UTC?
UPDATE
For the moment I am casting to Date and doing this
#{Dates.format(user.birthday.toDate, "dd-MM-YYYY")}
But maybe is a better way without casting
thank you
So, if I understood your question correctly, you are trying to achieve the following:
Parse date from a string using a date format
Print/Display the date in another format.
Try the below:
#{Dates.format(DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ").parseDateTime(user.birthday.toString), "dd-MM-YYYY")}

Date display Appery.io

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

converting a utc format date string to date object in Extjs

I have a date string in the format "2013-01-31T10:10:05.000Z". I want to convert this string to a Date object in extjs.
I have tried to use Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-dTH:i:s.uZ"). But it is returning undefined.
I also tried with new Date("2013-01-31T10:10:05.000Z"), but it is also returning undefined.
Note: I have tried in IE8 browser.
Could anyone please help me to convert the above date string to Date object?
Thanks a lot sra. Now I am getting the result as ...UTC+5:30... Is there any way to convert this in IST format?
Try Ext.Date.parse("2013-01-31T10:10:05.000Z","c");
The c is the format type for ISO 8601 formatted dates
See the Ext.Date API for more details on this or other available formats
That's because 'T' and 'Z' are special characters in the Date format: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date
You have to escape them like this: Ext.Date.parse("2013-01-31T10:10:05.000Z","Y-m-d\\TH:i:s.u\\Z")