How can I convert the Date datatype in to seconds since epoch?
unix_timestamp() in MySQL. It varies from platform to platform. What DB are you using?
If you have a Date in scripting, this will convert it to seconds since epoch (Java epoch is Jan 1, 1970)
date = ...
secondsSinceEpoch = data.getTime() / 1000
I have a date from a date picker component. I needed to get it into epoch seconds to use in a database query to compare against a timestamp. (t_stamp column in sqlt_data_xxx table to be precise)
Nathan, I’m using PostGres.
The solution I worked out was to use:
select extract(epoch from timestamp with time zone '"+system.db.dateFormat(date, 'yyyy-MM-dd HH:mm:ss.SSSZ')+"')
I like Carl’s solution better. Why the ‘/1000’? does getTime() return milliseconds since epoch?
yep - milliseconds. See the javadocs for details.