search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Change Date Format

Related article: ASP.NET Scheduler Tutorial
Asked by Amit Tiwari
10 months ago.

how to change "DayPilotScheduler1.VisibleStart" date format in dd/MM/yyyy To yyyy-MM-dd.

Answer posted by Dan Letecky [DayPilot]
10 months ago.

DayPilotScheduler1.VisibleStart is a DateTime object so you can get a custom formatted string from it using ToString():


See also here:

Comment posted by Amit Tiwari
10 months ago.

How to Solve it?
Error is :-

Conversion failed when converting date and/or time from character string.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string.

Source Error:

Line 75: da.SelectCommand.Parameters.AddWithValue("start", start);
Line 76: da.SelectCommand.Parameters.AddWithValue("end",end);
Line 77: DataTable dt = new DataTable();
Line 78: da.Fill(dt);
Line 79:

Source File: d:\Maik enviro\erp\DAL\Db.cs Line: 77

private void LoadAppointments()
DataTable table = DAL.Db.LoadAppointments(DayPilotScheduler1.VisibleStart, DayPilotScheduler1.VisibleEnd);
DayPilotScheduler1.DataSource = table;
DayPilotScheduler1.DataIdField = "ID";
DayPilotScheduler1.DataTextField = "Name";
DayPilotScheduler1.DataStartField = "App_Date";
DayPilotScheduler1.DataEndField = "AppointmentEnd";
DayPilotScheduler1.DataTagFields = "AppointmentStatus";
DayPilotScheduler1.DataResourceField = "Team_id";

DAL.Db.LoadAppointments Is:-

public static DataTable LoadAppointments(DateTime start, DateTime end)
SqlDataAdapter da = new SqlDataAdapter("SELECT ( Client_Master.First_Name + Client_Master.Last_Name) AS Name, Client_Master.Company_Name, Appointments.Team_id,Appointments.ID, Appointments.App_Date, Appointments.AppointmentEnd, Appointments.AppointmentStatus, Appointments.Remark FROM Appointments INNER JOIN Client_Master ON Appointments.Client_id = Client_Master.Client_id WHERE NOT (([AppointmentEnd] <= '" + start + "') OR ([App_Date] >= '" + end + "'))", "Data Source=;Initial Catalog=NaikEnviro;Persist Security Info=True;User ID=''''''''''''''''';Password=............;Connect Timeout=720000;");
da.SelectCommand.Parameters.AddWithValue("start", start);
DataTable dt = new DataTable();

return dt;


Comment posted by Dan Letecky [DayPilot]
10 months ago.

You can try replacing AddWithValue() method with the following code:

da.SelectCommand.Parameters.Add("start", SqlDbType.DateTime); 
da.SelectCommand.Parameters["start"] =start; 

This way you will prevent unwanted conversions to/from string.

Comment posted by Amit Tiwari
10 months ago.

Facing same error.

Comment posted by Dan Letecky [DayPilot]
10 months ago.

You are inserting the dates directly into the query string:

...(([AppointmentEnd] <= '" + start + "') OR ([App_Date] >= '" + end + "'))"

That's not how it's supposed to be done. You should switch to named parameters. Then the SQL server will handle it for you:

...(([AppointmentEnd] <= @start) OR ([App_Date] >= @end))"

The @start and @end placeholders will be replaced by the values supplied using Parameters.Add/AddWithValue:

da.SelectCommand.Parameters.AddWithValue("start", start); 
Comment posted by Amit Tiwari
10 months ago.

Currently My project is running. Thanks for all your great help. I simply couldn't have done without you!!!!!!

Thank you once again.

Comment posted by Dan Letecky [DayPilot]
10 months ago.

Great, thanks for the update!

This question is more than 6 months old and has been closed. Please create a new question if you have anything to add.