Date/Time formatting

Avatar

14-06-2007

I know this topic has been hashed and rehashed, but I am looking for example as to how to combine date and time in same field:



e.g. I have date/time field. I set binding to 'Date and Time'. Validation is 'date{MM/DD/YYYY} time{HH:MM}'



So far so good. However, I cannot set the right Display or Edit Pattern. In my 'calculate', I have:



var today = new Date();

var month = today.getMonth()+1;

var day = today.getDate();

var year = today.getFullYear();

var hour = today.getHours();

var minute = today.getMinutes();

this.rawValue = (month < 10 ? "0" : "") + month + "/" + (day < 10 ? "0" : "") + day + "/" + year + " " + hour + ":" + minute;



I want to have format as MM/DD/YYYY HH:MM. If I put that into Display Pattern, it complains about invalid pattern, it accepts 'date{MM/DD/YYYY} time{HH:MM}'. But then displays nothing in the Preview.

Replies

Avatar

15-06-2007

probably a stupid way to do it but it might do what you want.



Javascript on a regular text field:



this.rawValue = util.printd("mm/dd/yyyy",new Date()) + ' ' + util.printd("HH:MM",new Date());

Avatar

15-06-2007

Well, if I change to Textfield, everything displays, but now the validation no longer works, and it does not actually accept any changes when I tab out.

Avatar

Avatar

gkaiseril

Avatar

gkaiseril

gkaiseril

15-06-2007

Have you set the "Date Format" on the "Binding" tab, the "Display Pattern" on the "Field" tab and the "Validation Pattern" on the "Value" tab?



All of these fields need to match or be of a compatible pattern.

Avatar

18-06-2007

Here is how I achieved it:



Create a textfield, data format is plain text, type is 'Calculated, user can override'. In 'Calculated' event, place string to set rawValue, e.g. MM/DD/YY hh:mm. In 'Exit' event, parse the date, and the time separately, and check the format manually.