Converting datepicker to unix timestamp
Converting datepicker to unix timestamp
Hello,
i'm using a Oracle database with a number column which contains unix timestamps for dates. I use moment.js so all timestamps will shown as human readable datas in the datatable view. Inside the editor i use the option type 'date' and so the editor uses the datepicker for editing and creating new dates.
How can i convert these datas to unix timestamp before datables tries to write this into the database?
Thanks a lot for your help!
Javascript:
label: "Starting",
name: "dstart",
type: "date",
def: function () { return new Date(); },
dateFormat: "dd.mm.yy"
Ajax:
Field::inst( TB_KAPA_DATEN . '.' . C_KD_START, 'dstart' )
This question has an accepted answers - jump to answer
Answers
Hi,
Use a get and set formatter to transform between the unix time stamp and the human readable format. Specifically the
dateTime
formatter.You can see it in use here.
Allan
Hmmm, as i understand the get and set formatter you can "only" change the appearance, i.e. year to the start or to the end of the string, and not the value itself.
In my case i have to convert the date to a number which represents the date in seconds.
I tried this:
Before i tried this, i always get the Oracle-Error: ORA-01722 invalid number, because Oracle expected a number but recieved a date (string?).
Now i get no error messages but nothing happens. I tried to add a new row and nothing happend.
Editor:
Server Script:
Server Output:
For the get formatter, yes. It reads from the db and formats for output.
The set formatter however reads the data from the user's submission and modifies the data before writing it to the db.
You'll need to use the
dateTime
method I suggested above, rather thandateFormatToSql
. WithdateTime
you can specify the input format (i.e. what is submitted) and the output format (what is written to the db). In this case you want to have PHP output unix time stamps (since Oracle doesn't use ISO8601 like every other db on the planet by default ).Allan
Yes, i know. It's a real pain in the *** with Oracle. But i have no choice, the customer is using Oracle.
I'll try dateTime later and will report.
Sometimes it's so easy, that you can't really see it.
This converts the date to unix timestamp (server script):
Just that easy!