Pergunta

I need your help with a date and time format issue.

Firstly, what is happening is that I am entering the correct date date format of dd/mm/yyyy into my input textbox. Ex. 01/04/2014 April 1, 2014

Secondly, I am writing that value from the input textbox into my MDB database: dd/mm/yyyy. Ex. 01/04/2014

Thirdly it seems that my MBD is automatically re-arranging my date of dd/mm/yyyy into yyyy-mm-dd (US standard)

So that when I retrieve the date from my mdb I get a long date of: Sat Jan 4 00:00:00 EST 2014

I guess I would need a javascript function that would take the long date, convert it to yyyy/mm/dd then re-organize the string to dd/mm/yyyy (UK standard)

Foi útil?

Solução

Something else to consider.

Is your DB field actually a datetime field?

The string format for dates is completely disassociated from the database internal representation. It's likely not so much rearranging the date as implicitly converting it to the date/time format that was set up as default for the database.

It just happens that "1/4/2014" is both a valid UK and US format so without explicit conversion the date stores using the DB default. "31/4/2014" would likely cause an error.

Just a thought

Outras dicas

Try using a JavaScript Date object. You should be able to pass that long date string into it. Once you have it in the Date object, you can use its methods for easy date conversion to whatever format you want. For example, if you want to show the UK standard on the UI, you could just do something like:

myDisplayDate = myDate.day + "/" + myDate.month + "/" + myDate.year;

You might have to put toString() at the end of those methods, I don't remember if it's smart enough to convert automatically.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top