Saving date field as dd/mm/yyyy rails - postgresql

We have a date_of_birth field of date type in our User model.
When I am trying to save my User object.
u = User.last
u.date_of_birth = "31-03-1987"
u.save
results:
u.date_of_birth
=> Tue, 31 Mar 1987
but If I replace - with /
u.date_of_birth = "31/03/1987"
u.save
results:
u.date_of_birth
=> nil
Question
Is this is a default behaviour?
Or Am I missing something?

It will be set obviously nil because date_of_birth does not hold a valid format.
The standard DB format for datetime is YYYY-MM-DD HH:MM:SS
Using postgres db for higher rails version i.e. Rails 3+ you cannot get such issue,
> u.created_at = '03/04/2017'
# => "03/04/2017"
> u.created_at
# => Mon, 03 Apr 2017 00:00:00 IST +05:30
Issue does exists in older version of ruby. I recommend you to either get updated or change format of string date input

Related

Dateparse MON in Tableau

I have a data source that returns a date as a string in the form of 'MON YYYY' (APR 2014, MAY 2014, etc.).
I tried making a calculated field off of this information with the following formula:
DATEPARSE('MMM YYYY', [Field1])
This is a sample set of the data I'm getting (I added the pipe as a divider):
Field1 || Calculated Field
APR 2014 || 12/22/2013
APR 2015 || 12/28/2014
APR 2016 || 12/27/2015
AUG 2014 || 12/22/2013
AUG 2015 || 12/28/2014
AUG 2016 || 12/27/2015
I've also tried to add a day field, but that results in the same incorrect data as above:
DATE(DATEPARSE('dd MMM YYYY','01 ' +[Field1]))
Is there something I'm perhaps misunderstanding about the dateparse function?
It turns out that YYYY means something totally different than yyyy. The capitalized MMMwas necessary for the MON type description. This worked for me:
DATE(DATEPARSE('MMM yyyy',[Field1]))
If you date the date off you'll get the hour, minute, second fields as well.
Dateparse converted it from a string [Field1] into a Date type using the aforementioned format of three digit month, a space, and a four digit year (e.g. AUG 2014 -> 8/2/2014).

Angular2 - convert unfortunately date

I have a problem - I use c# Web.api and Angular2. Thats works but Angular convert the date which I do not want / need. The date of the database is correct and angular add 1 hour
{{item.createdate | date:'H:mm' }}
So it shows 20:30 instead of 19:30 which is stored in the database :(
This is part of json repsone:
"createdate": "2016-11-29T19:30:00",
How can I solve this?
Thank you
Ralf
The Reason is there's no timezone information in the datetime string from the database result.
var date = new Date('2016-11-29T19:30:00');
console.log(date); //Tue Nov 29 2016 20:30:00 GMT+0100 (CET)
Written in the Angular2 documentation about the Date Pipe here.
The expression expects a valid datestring format:
YYYY-MM-DDThh:mmTZD (eg 2016-11-29T19:30+01:00)
var date = new Date('2016-11-29T19:30+01:00');
console.log(date); // Tue Nov 29 2016 19:30:00 GMT+0100 (CET)

Issue saving a string as ISO date format

I'm trying to save a date to MongoDB from FullCalendar in my Grails application.
I'm trying to parse the string 2015-12-27T00:00:00.000Z into the below format:
def startDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.start)
def endDate = new Date().parse("YYYY-MM-dd'T'HH:mm:ss.SSSXXX",it.end)
But, weirdly when I print the formatted date, I get Sun Dec 28 05:30:00 IST 2014. I don't know what or how that particular date is picked.
You should use lowercase y for year. Uppercase Y is for "Week year".
new Date().parse("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", "2015-12-27T00:00:00.000Z")
===> Sat Dec 26 19:00:00 EST 2015
import java.text.SimpleDateFormat;
println new SimpleDateFormat("yyyy-MM-dd HH:mm:ssX").parse("2018-07-30 09:57:15 +0800")

How to format a date in Ext JS 3?

I have a date value like this ;
Date {Fri Feb 13 2015 02:00:00 GMT+0200 (GTB Standart Saati)}
I get it from a grid column with ;
selectionModel.getSelected().data['date'];
And column model date format is 'd/m/Y'. It shows in grid well (d/m/Y).But when i get selected value it returns a date format doesn't like 'd/m/Y'. How can i format this date to set to a textfield ?
According to ExtJs Docs
var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toDateString()); // prints Wed Jul 28 1993
Edit:
Please use Ext.Date.format to format the date:
Ext.Date.format(d,'d/m/Y');
According to ExtJS 3.4 Docs Date object is extended with .format() method.
So you should be able to just do
var d = new Date();
d.format("d/m/Y");

JavaFX8 Convert String to date using DateTimeStringConverter

I would like convert string to date (dd/MM/YYYY) - this is useful for compare dates in TableColumns.
so i use DateTimeStringConverter (the string "01/11/2014" is a value of DatePicker)
DateTimeStringConverter format = new DateTimeStringConverter(Locale.FRANCE,
"dd/MM/YYYY");
Date d1 = format.fromString("01/11/2014");
d1.toString()
I don't obtain the right date but this date = "Mon Dec 30 00:00:00 CET 2013" !!!
I don't understand what is the problem (which in fact should not be a problem) ?
Any ideas ?
Thank you in advance
Fabrice