Combobox column in Devexpress ASPxGridView shows Datetime instead of Date - asp.net

I made that one column id GridView is lookup from stored procedure. Stored procedure is joining two tables and date in queston is date, not date time, but in GridView it's shown as Date + 0:00:00.
Any idea how to fix this?
(Ordinary columns dates are fine, but this lookup column is wrong).

Try with DisplayFormatString: documentation and demo. And for general date and time format strings documentation look here.

Related

OUTPUT <NULL> WHEN SELECTING DATE FROM DATETIME - SQLITE

I'm new to the SQL world and im going crazy trying to figure out how to SELECT date from a datetime field in SQLITE.
Example: value <11/11/2005 14:56>, i just want to select <11/11/2005> for EVERY ROW.
I tried strftime(), date(), CAST() and other functions but the output its always NULL.
For example i tried querying SELECT strftime('%d/%m/%Y' , columnname) AS date FROM tablename;
OUTPUT: "NULL" in every row
Can someone help me understand what im doing wrong and how can i fix it? Thank you!!!
It always returns NULL because MM/DD/YYYY is not a valid sqlite date format. Treat the column as a string and use substr and instr to drop off the time portion. Something like (no guarantees, check the doc!)
SELECT substr(columname,0,instr(columnname,' '))
Re comment "how to order by the date in descending order"
This problem is a good argument (the best argument?) for storing the date in a sqlite date/time format. There is a strategy in this post for converting MM/DD/YYYY to YYYY-MM-DD (which sorts dates correctly).
If it's not too late, it would be advisable to change the date storage to a valid sqlite date format. strftime can be used to present the date as desired, and sorting will be accurate.

Error with dates when filling a datatable

I am trying to fill a datatable in vb using SQLiteDataAdapter from a SQLITE database. There are 3 fields in the table that contain dates and they appear as either recent dates or "1899-12-30" . The Fill command generates a "String was not recognized as a valid DateTime." error. I cannot find a date entry that does not look valid, except "1899-12-30", is this a valid date?
Any other thoughts would be appreciated.
Brad
The short answer is 'yes'. I built a table with the three possible ways of storing dates, thus:
CREATE TABLE `JustDate` ( `Date_1` INTEGER, `Date_2` TEXT, `Date_3` REAL )
Then I populated each of those fields in one record with the value you suspect.
And then I did a trial query against the fields to see if sqlite would treat them as proper dates.

Format date from lookup table

My report has a data lookup table with dates in dd/mm/yyyy formart. When I bring it into Crystal it changes the data type to date-time instead of just date.
I tried converting to just a date within Crystal, but when I run a lookup based on parameters (10-1-2016 - 10-31-2016) I get a running cycle of dates. As soon as it hits 10-31-2016 it starts over from 10-1-2016.
I tried setting it to not provider duplicate values to no avail. How I could be doing this better?
If you just need to display the date without the time value, you can format the field when it displays in your report as "System Default Short Format" in the Format Editor. (Date and Time tab)
Otherwise leave the date as-is and create a seperate Formula Date({table.Field}) to use as "just the date". This way you keep the original datetime value as-is, but can use your new Formula when the time value needs to be removed.

Finding Difference in dates in SQL Query

I have a varchar column in sql database which stores in the format (dd//mm/yyyy). I want to find difference between the System Date(ie. when a website is hit)and the column where i have stored date in (dd/mm/yyyy) and display the results of 2 columns of a table in a grid view. Can you please help in this.?
You can use DATEDIFF() function.
Syntax
DATEDIFF(datepart,startdate,enddate)
In your query
SELECT DATEDIFF(day,CAST(dateColumn as datetime),CAST(TodaysdateColumn as datetime)) as dateDiffColumn
Edit
SELECT DATEDIFF(day,CONVERT(datetime,dateColumn,103),CONVERT(datetime,TodaysDateColumn,103)) as dateDiffColumn
This gives difference in dates in terms of number of days.
Then you can bind calculated column to Gridview column.
<asp:BoundField Text='<%#Eval("dateDiffColumn")%>' runat="server">
Parse the date string into a DateTime variable using DateTime.ParseExact. You can then compare the two dates as DateTimes and get the difference.

Manually Binding A RadGrid with non-standard date format?

I attempting to manually bind a radgrid to a view. The issue is I need to query by dates and sort by dates, however the original developer stores the dates as strings in the DB and with a non-standard format of "yyyyMMdd"
Is there a way to automatically bind it, or do i have to do a manual bind? If i have to do it manually what is the best way to do this? Read the view into a datatable? Re-Cast all of the dates, and then bind the datatable to the grid?
In the NeedDataSource event use a LINQ selector to get the values and convert the date stored in the database to a TimeStamp.
Alternatively you can modify the given column to have a TimeStamp value in the database (make sure you are using a transaction, not allow writes to that table and save all the values temporarily somewhere so you can load them back, maybe into a temporary table having the id and the date).

Resources