i'm done created code in express.js for save data into postgres and cassandra, code include for get time from server :
var currentdate = new Date();
var datetime = currentdate.getFullYear() + "-"
+ (currentdate.getMonth()+1) + "-"
+ currentdate.getDate() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
i use variable datetime for save data into postgres and cassandra, in postgres data datetime is 2015-09-17 09:39:27 but in cassandra is 2015-09-17 02:39:27+0000 there is different in time value
time in postgres is correct
how can i fix this ?
thx
Related
I am trying to write a query where I can get content from a location in AEM dated from today's day back 24 months, but the date is not based on the publish/modify/creation date. They are asking for the dates to be based on the content called the "publish release date".
I have the following working off the creation date:
String sqlstmt = "SELECT * "
+ "FROM [nt:unstructured] AS comp "
+ "WHERE ISDESCENDANTNODE(comp, '" + pathLocation + "') "
+ " AND [sling:resourceType] = 'nvenergy/components/content/pressrelease' "
+ " AND comp.[jcr:created] >= "
+ " CAST('" + julianEndDateString + "T00:00:00.000Z' AS DATE) "
+ " AND comp.[jcr:created] < "
+ " CAST('" + julianCurrentDateString + "T00:00:00.000Z' AS DATE) "
+ " ORDER BY 1 ASC";
but I really need it to be off the content's "publish release date" found here:
...
if (currentNode.hasProperty("pressreleasepublishdate")) {
Calendar publishedDate =
currentNode.getProperty("pressreleasepublishdate").getDate();
...
Can I do a join or used something to use the node's property for the release date instead of the [jcr:created] as my range? Or do I have to execute the query hold it in a temp list and resort based on the node's property for the release date?
in my DB2 database, I have the UTC data in the format 1160307144500000 and a field which indicates the time difference respect to local date, for example 3600 in seconds.
I need sum to UTC date the 3600 secs so I can get 1160307154500000.
Here is some DB2 code snippet
TIMESTAMP('1900-01-01 00:00:00')
+ INT(SUBSTR(utc_data,1,3)) YEAR
+ INT(SUBSTR(utc_data,4,2)) + 1 MONTH
+ INT(SUBSTR(utc_data,6,2)) DAY
+ INT(SUBSTR(utc_data,8,2)) HOUR
+ INT(SUBSTR(utc_data,10,2)) MINUTE
+ INT(SUBSTR(utc_data,12,2)) SECOND
+ 1000*INT(SUBSTR(utc_data,15,3)) MICROSECOND
+ diff_data SECOND
I'll leave the code to transform the timestamp back to the original format up to you :)
I have a query log table (system table), it returns:
After attach the date and time, I need convert:
'20160404105625'
To dateTime type:
2016-04-04 10:56:25.00
You'll need the string in the format "20160404 10:56:25" to be able to convert it to the desired result:
SELECT CONVERT(DATETIME, run_date + ' ' + LEFT(run_time, 2) + ':' + SUBSTRING(run_time, 2, 2) + ':' + RIGHT(2, run_time))
FROM your_table
I'am using timestamp data type on pg9.4, but there come very strange problem with to_json.
now i am in Shanghai, UTC+08:00 timezone.
see below:
conn.createStatement().execute("set time zone 'UTC'");
String sql = "select to_json(?::timestamp) as a, to_json(current_timestamp::timestamp) as b";
PreparedStatement ps = conn.prepareStatement(sql);
Timestamp timestamp = new Timestamp(new Date().getTime());
ps.setTimestamp(1, timestamp);
ResultSet rs = ps.executeQuery();
while(rs.next()){
System.out.println("a " + rs.getString("a") + ", b " + rs.getString("b"));
}
output:
a "2015-09-24T16:52:42.529", b "2015-09-24T08:53:25.468191"
it's mean when i pass a TIMESTAMP parameter to pg with jdbc, the timezone is still in shanghai, not UTC.
this problem is not due to to_json function, i have make a table with one timestamp column, this problem still exits, the code of above is shortest sample.
how to let's all timestamp work in UTC timezone?
You need to set Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));, Before you create your prepared statement.
UPDATED CODE SNIPPET
conn.createStatement().execute("set time zone 'UTC'");
String sql = "select to_json(?::timestamp) as a, to_json(current_timestamp::timestamp) as b";
Calendar tzCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
PreparedStatement ps = conn.prepareStatement(sql);
Timestamp timestamp = new Timestamp(new Date().getTime());
ps.setTimestamp(1, timestamp);
ResultSet rs = ps.executeQuery();
while(rs.next()){
System.out.println("a " + rs.getString("a") + ", b " + rs.getString("b"));
}
This way you will be able to set timezone to UTC in your JDBC call.
If you want to run the whole application/JVM in UTC, set -Duser.timezone=UTC flag while starting JVM.
HTH.
i'm getting the sum() of the records of one month in this year.. here it is the method to get the month , but how can i get only the month of this year and not from the last year?
public Cursor calculate(String month){
return db.rawQuery("Select " + "sum(" + CN_GA + ")" +
" from " + TABLE_NAME + " where strftime('%m', " + CN_DATE + ") = '" + month +"'", null);
}
Note: mi date is in "yyyy-MM-dd HH:mm:ss" format.
thx for the answer in advance , and sorry for my english.
Combine with the condition
where strftime('%Y', yourdate) = "2015"
That is
" where strftime('%Y:%m', " + CN_DATE + ") = "
+ "'" + year + ":" + month + "'"