datatable.select("DateTime column") - datatable

I have a DataTable with a DateTime column.
First, I have a problem with sorting :
DataTable.DefaultView.Sort = "CREATED_DATETIME asc";
it doesn't work properly,
Secondly, I have a problem with select :
DataTable.Select("CREATED_DATETIME <" + FromDate +");
( FromDate is a radDatePicker control).

As far as the getting the value from your RadDatePicker (Telerik?) I've not used this but it does look like you have more steps before that will work http://www.telerik.com/help/aspnet-ajax/mvc-getting-values-raddatepicker-raddateinput.html
What are the symptoms of the sort not working properly?

Related

Lotus sorting view on orderdate does not work properly

I have created a view in which I also have a column which holds dates. This column can be sorted on ascending and descending. This is my column properties value:
But the problem is that the view does not sort the dates properly:
And here a screenshot of the orderdate field itself:
And here screenshot of the document with the orderdate that is out of order in the view:
Update
Some documents had the orderdate as text instead of date.. I create these documents through a java agent. The field orderdate I fill in like this:
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
But it is saved as text instead of date. Anyone knows why?
Problem was that orderdate field was set by a backend agent and this field was set with a string.
I know saved the current time as a DateTime object and now it works:
DateTime timenow = session.createDateTime("Today");
timenow.setNow();
docOrder.replaceItemValue("Orderdatum", timenow);
It's not clear to me why it's not working for you, but you can brute force it with something like this in the column formula
dateForSure := #TextToTime(OrderDatum);
#Text(#Year(dateForSure)) + "-" + #Text(#Month(dateForSure)) + "-" + #Text(#Day(dateForSure));
Also: your Java code saves a text value because the format() method of SimpleDateFormat returns a StringBuffer. The ReplaceItemValue method generates a text item when its input is a String or StringBuffer. Assuming your form defines OrderDatum as a Time/Date field, you can call Document.ComputeWithForm in your code to force it to convert the text item to a Time/Date. Another method - probably preferable given the potential side-effects of calling ComputeWithForm would be to create a DateTime object in your Java code and pass it to the ReplaceItemValue method instead.
It's because formatterDatumForField.format(currentDateForField) returns a String instead of a date/time value. Assuming that currentDateForField is a date/time value, you should change
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
to
docOrder.replaceItemValue("Orderdatum",currentDateForField);

Unable to extract Model Data Using created_at in rails 2 application

#versions = Version.find_all_by_created_at(2015-05-07)
#versions = []
datatype for created_at(datetime)
Please i want extract data by passing only date to a model .
I think it is simple
If you want to do it for the current date then you can just use Date.today
Version.where(created_at: Date.today.beginning_of_day..Date.today.end_of_day)
Otherwise as #davidesantangelo has mentioned that is fine, except using parsed "date" variable, you can use "date.beginning_of_day"
e.g.
selectDate = Date.parse('2015-05-07')
Version.where(created_at: selectDate.beginning_of_day..selectDate.end_of_day)
That will form query like this:
SELECT "versions".* FROM "versions"
WHERE ("versions"."created_at"
BETWEEN '2015-04-28 00:00:00.000000' AND '2015-04-28 23:59:59.999999')
And without "beginning_of_day" it will have query like
SELECT "users".* FROM "users"
WHERE ("users"."created_at"
BETWEEN '2015-04-28' AND '2015-04-28 23:59:59.999999')
So I would prefer it with beginning_of_day.
try this
date = Date.parse('2015-05-07')
and then
Version.where("created_at <= ? AND created_at >= ?", date + 1, date - 1)
Created at is a datetime so it would be very specific. You need to search within the same day
date = Date.parse('2015-05-07')
Version.where(created_at: date..date.end_of_day)

ASP.NET GridView fail to sort a Date passed as string

Hi I am building a site which has a gridview with AutoGenerateColumns = True, the issue that I am having is the Sort condition using a dataview does not work correctly for example. If I have the following records already displayed on the gridview:
Name Address Date (MM/DD/YYYY)
Julio XYZ Australia 12/25/2010
David 1234 New Zealand 12/26/2010
Erika 5555 Singapore 12/14/2011
If I do the sorting this way:
Dim dt As DataTable = Me.GetDataTable(Me.GetQuery(Sentence, params))
Dim dv As DataView = dt.DefaultView
dv.Sort = SortExpression & " " & SortDirection
gv.DataSource = dv
gv.DataBind()
The result in the grid is :
Name Address Date (MM/DD/YYYY)
Erika 5555 Singapore 12/14/2011
Julio XYZ Australia 12/25/2010
David 1234 New Zealand 12/26/2010
So the problem it seems to be the sort is only taking in consideration part of the date only the first five characters instead of the whole string.
The values for SortExpression is the ColumnName for Date which in the datasource is CallDate and the SorDirection Value is ASC
The Me.GetDataTable(Me.GetQuery(Sentence,paramas)) is just a way to populate the datatable with the records from the Database.
Another thing, sadly I cannot change the format of the Date because is a business requirement to be presented that way, also I am not allow to use third party controls because the budget of the project. :-(
Thanks for the any idea in advance.
First I want to confirm that whether your Date is DateTime type, if yes,
please try to sample as below, hope these will give you a hand.
Dim dt As DataTable = Me.GetDataTable(Me.GetQuery(Sentence, params))
dt.DefaultView.Sort = "Date ASC" ''Sort with Asc.
gv.DataSource = dt
gv.DataBind()

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).

Get the the most recent and the one before the most recent item

I have a table with many anniversaries : Date + Name.
I want to display the next anniversary and the one after with Linq.
How can i build the query ?
I use EF
Thanks
John
Just order by date and then use the .Take(n) functionality
Example with a list of some objects assuming you want to order by Date then Name:
List<Anniversaries> annivDates = GetAnnivDates();
List<Anniversaries> recentAnniv = annivDates.OrderBy(d => d.Date).ThenBy(d => d.Name).Take(2).ToList();
If the anniversaries are stored in regular DateTime structs, they may have the 'wrong' year set (i.e. wedding or birth year). I suggest writing a function which calculates the next date for an anniversary (based on the current day) like:
static DateTime CalcNext(DateTime anniversary) {
DateTime newDate = new DateTime(DateTime.Now.Year, anniversary.Month, anniversary.Day);
if (newDate < DateTime.Now.Date)
newDate = newDate.AddYear(1);
return newDate;
}
Then you proceed with sorting the dates and taking the first two values like described in the other postings:
(from e in anniversaries orderby CalcNext(e.Date) select e).Take(2)

Resources