golang Compare time size - go

I want to make a comparison between the current time and the database data. My code is:
var PayBlockedLog[] model.PayBlockedLog
global.DB.Where("status = ?",0).Find(&PayBlockedLog)
for i := 0; i <len(PayBlockedLog); i++ {
if time.Now().Unix() < PayBlockedLog[i].UnsealTime{
}
}
It seems that I should have PayBlockedLog[i].UnsealTime convert to int64.
After trying, there was no effect

Rather than fetching and then filtering, do the filter in the query. This will save time and memory, as well as avoid time zone issues.
I don't know what database you're using, nor the column type of UnsealTime. If it's a timestamp or datetime (which it should be) check it against current_timestamp.
global
.DB
.Where("status = ? and current_timestamp < UnsealTime", 0)
.Find(&PayBlockedLog)
If it's seconds since the Unix epoch, consider converting it to a normal timestamp column so date/time functions can be used. There are several ways to accomplish this while keeping the old column for compatibility.
Otherwise, you can convert the current time to epoch seconds. How you do this depends on the database. Here it is in Postgres.
global
.DB
.Where("status = ? and extract(epoch from current_timestamp) < UnsealTime", 0)
.Find(&PayBlockedLog)

Related

Last None Blank DAX Measure

I have the results as:
but need the results to appear as:
ie. where the last value with data will fill up the entire horizon for that year, each month defaulting to the last month with data.
Attempting to use the DAX as:
[Land Dev YTD]:= VAR LastNoneblankDate = CALCULATE(max('Date'[Date]),FILTER(Hyperion,[Land Dev] > 0)) return IF([Land Dev] = 0,CALCULATE([Land Dev],FILTER(ALL('Date'),'Date'[Date]=LastNoneblankDate)),[Land Dev])
Should in theory be sufficient, ie. supplant the result, where 0, to the value whereby the data is last present. However, the result is:
as it blows away all the other dates where there is not data.
How can I get this resolved?

net.fortuna.ical4j.model.DateTime to ORACLE date

I have net.fortuna.ical4j.model.DateList which contains
net.fortuna.ical4j.model.Date objects
The output is: 20170522,20170523,20170525
(UTC time zone)
I have to convert it to ORACLE date in SystemDefault timeZone.
I tried to do this:
List<DATE> result = new ArrayList<DATE>
for(Date d : rdates){
result.add(new DATE(new Timestamp(d.getTime()));
}
But oracle date is different as expected.From net.fortuna.ical4j.model.Date 20170522,20170523,20170525 I got 20170521,20170522,20170524 ORACLE DATE.
There is shifting. How can I handle this?
Ical4j Date objects have an underlying timezone that is not defined as part of the formal specification (an implementation quirk).
By default this timezone will be UTC, however you can change this to system default using the following compatibility hint:
net.fortuna.ical4j.timezone.date.floating=true

Epoch time difference in Pig

I have 3 columns which contains start_time , end_time and tags. Times are represented in epoch time format as shown in example below. I want to find the the rows which have 1 hour time difference between them.
Example:
Start_time End_Time Tags
1235000081 1235000501 "Answered"
1235000081 1235000551 "Answered"
I need to fetch the tags column if the time diff is less than an hour.
I want do it in PIG - can anyone kindly help?
input.txt
1235000081 1235000501 Answered
1235000081 1235000551 Answered
pig script
A = Load '/home/kishore/input.txt' as (col1:long, col2:long, col3:chararray);
B = Foreach A generate ToDate(col1) as startdate,ToDate(col2) as enddate,col3;
C = Filter B by GetHour(enddate)-GetHour(startdate) == 1;
Dump C;
you can filter the row based on your condition like >,< ,==
In case if you want to keep date fields as timestamps the solution is following:
data = LOAD '/path/to/your/input' as (Start_Time:long, End_Time:long, Tags:chararray);
data_proc = FOREACH data GENERATE *, ToDate(Start_Time*1000) as Start_Time,ToDate(End_Time*1000) as End_Time;
output = FILTER data_proc BY GetHour(End_Time)-GetHour(Start_Time) == 1;
Dump #;
The one crucial thing is that Pig ToDate UDF needs a timestamp up to milliseconds precision thus you will have simply multiply your date fields by 1000 before using this UDF.

How can I compare 2 dates in a Where statement while using NoRM for MongoDB on C#?

I have a table in Mongo. One of the fields is a DateTime. I would like to be able to get all of the records that are only for a single day (i.e. 9/3/2011).
If I do something like this:
var list = (from c in col
where c.PublishDate == DateTime.Now
select c).ToList();
Then it doesn't work because it is using the time in the comparison. Normally I would just compare the ToShortDateString() but NoRM does not allow me to use this.
Thoughts?
David
The best way to handle this is normally to calculate the start datetime and end datetime for the date in question and then query for values in that range.
var start = DateTime.Now.Date;
var end = start.AddDays(1);
...
But you'd also be well advised to switch to the official C# driver now. You should also use UTC datetimes in your database (but that gets more complicated).

DateTime Comparison in LINQ

I am ran into the following issue.
Take a look at the following where clause.
Where(x => x.CreateTS <= dateParameters.CreationDate.ToDateValue &&
x.CreateTS >= dateParameters.CreationDate.FromDateValue)
CreateTS is a Timestamp column in the table. so when my dateparameters are todate = 01/28/2010 12:00A.M" fromdate= "01/26/2010 12.00A.M" (c# DateTime types) my query doesnot retrivies the table records whose CreateTS look like 01/28/2010 1:45A.M and above just differeing in the timestamps.
I just wanted to do comparison and dont want to compare the timestamps. any help would be appreciated.
Just look at the .Date portion of the DateTime:
Where(x => x.CreateTS.Date <= dateParameters.CreationDate.ToDateValue && x.CreateTS.Date >= dateParameters.CreationDate.FromDateValue)
As a side note:
Personally, I would put from first, since it's a bit easier to follow from a readability standpoint:
Where(x => x.CreateTS.Date >= dateParameters.CreationDate.FromDateValue && x.CreateTS.Date <= dateParameters.CreationDate.ToDateValue)
(I find it easier to think of being between two values as being >low and
Edit: You didn't specify that you were using the EF LINQ providers, which do not allow you to do Date. You can, I believe, handle this by looking forward one day, and using < instead of <= for your "to" comparison:
Where(x => x.CreateTS >= dateParameters.CreationDate.FromDateValue && x.CreateTS.Date < dateParameters.CreationDate.AddDays(1).ToDateValue)
#SARAVAN, AFAIK timestamp columns cannot be used in comparisons like that. A timestamp columns are mapped as byte[] (byte array) in EF. If comparisons like that are needed, I suggest to change the timestamp column in database to a datetime one.
only to quote from MSDN:
The SQL Server timestamp data type has nothing to do with times or dates. SQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database.
Interesting moment here is that
01/28/2010 12:00A.M actually in 24 hour format is 00:00 while 01/28/2010 1:45A.M is 01:45 and that seems to be the reason why those records are not returned. The midday will be 01/28/2010 12:00P.M

Resources