Outputting datetime date to dropdown list from SQL Server database - asp.net

I have a webpage that populates a dropdown control using SqlDataSource.
I want to return date values from a table and output them into the dropdownbox,
The code I have to do this, which works in the query builder is as follows:
SELECT DISTINCT CONVERT (varchar(10), Appointmentdatetime, 103)
FROM Visit AS date
However when I run this, the following error occurs
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
When I modify the query to
SELECT DISTINCT
CONVERT(VARCHAR(10), Appointmentdatetime, 126)
FROM Visit AS date
it behaves correctly.
I need the date to output to dd/MM/yyyy. Can anyone offer any help on the problem?
Thanks

You could also try this
SELECT convert(varchar, cast(Appointmentdatetime as date), 103) FROM Visit as date

try this one
SELECT DISTINCT CONVERT (Date, Appointmentdatetime, 103) as dates FROM Visit

Related

Error during compare date format in sqlite query

I was writing an application on c#, which is save DateTime to the Text field in the database.
Format of date is:
'1/15/2020 14:48:44', '2/11/2020 12:53:59' and etc
Now I want to get records with SQL query by the last few days.
I understand that I need convert text to date, and compare. But SQL query return 0 results. My query is:
select * from LogRootProcessing where strftime(dateparsing) < strftime('%MM/%DD/%YYYY %HH:%MM:%SS','2/11/2020 12:53:59')
Could you please advise how to fix the query?
Thanks in advance.

How the where clause will work for the date field in the teradata

I would like to apply a where clause on the date field in the teredata, but it shows empty records. Below is the query used to get the data.
select * from table name where date = '2019-05-01'
Kindly suggest the correct format.
Try the below format:
select * from table x where date = DATE '2019-05-01'
Check this site

Timestamp in SSRS date parameter

I am working on an ssrs report with fetchxml as the data source. I have two date parameters in the report. When we provide different dates in from and to parameter , the report works without any issue. But if we provide the same date for both the parameters then the report shows no data. I know that its because of the timestamp. How can i add the timestamp "00.00.01" to the from and "23:59.57" to the to parameter.
Any suggestion would be of great help.
Thanks in advance.
Sandeep
You have to add this to your SQL Query in dataset
eg.
where somedate between #startDate+' 00:00:00' and #enddate +' 23:59:59'

sqlite DATETIME formatting and ordering, what am I doing wrong?

I have a number of "DATETIME's" for the following form e.x.:
2014-01-15T19:30:00-0800
I am successfully inserting them into an sqlite table that I created with the following statement:
CREATE TABLE STUFF(id unique,date_time DATETIME)
When I query using the statement below I get all the dates I inserted back but not ordered.
SELECT * FROM STUFF ORDER BY DATETIME(date_time) DESC;
I'm guessing this is a formatting issue but I'm not sure. Can anyone spot what I'm doing wrong?
This is not a date format supported by SQLite;
a time zone indicator must have the form ±HH:MM:
> SELECT DATETIME('2014-01-15T19:30:00-0800');
> SELECT DATETIME('2014-01-15T19:30:00-08:00');
2014-01-16 03:30:00

how to insert date in custom format in sql server table

recently i was working on windows based application in .net, where i have form which has field know as Joining date, which datetimepicker control, whenever user submits the form all the details goes in the sql server table, now the issue is for the date of joining field, sql server inserts its own datetime stamp, as the field is datetime type, but i want to insert the joining date as dd.MM.yyyy, so i used Convert.. like below...
CONVERT(VARCHAR(10), #JoiningDate, 104), i checked this statement in select query with #JoiningDate replaced with GetDate(), it showed me expected results but when i try to insert record, it does not insert record as expected... i am using SP, in sql server 2008, enterprise edition...
can anyone please tell me why this happening...
please reply as soon as possible as it is of utmost important.
Regards
Abbas Electricwala.
your problem may have something to do with the type of your table column. you see, if the column's type is datetime,with your convert operation, you are getting the date value the exact way you want it, but since your column type is datetime, sql will insert a datetime value to it.
you can try and change the column type to varchar(10), and see if it makes a difference.

Resources