Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a datetime field in sql table.
From c#, I also have datetime type but it is supposed to store only time so I am sending it 01/01/0001 09:49:44.
But while storing it in database it throws error:
that system.dattime cannot be converted to Timesapn.
Use the TimeOfDay property of the DateTime object
DateTime input = DateTime.Parse("01/01/0001 09:49:44");
TimeSpan result = input.TimeOfDay;
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am not that much experienced in asp.net MVC. I want to display date in correct format. But it is showing some number instead of that.
Below is my screenshot of the problem.
Here is my code where I convert date.
dateTime[i] = Convert.toDateTime(orderDetail.Rows[i]["joiningDate"].toString());
use this. you are not getting date in correct format so first convert it into string format and then to date time
Convert.ToDateTime(Convert.ToDateTime(orderDetail.Rows[i]["joiningDate"]).ToString("MM/dd/yyyy"))
To convert a date to a proper string, you can use DateTime.ToString(string format)
so:
DateTime.Now.ToString("dd-MM-yyyy")
will display as 10-03-2018.
So on your page you'll have to use .ToString on your date, with the format you want to use.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have .CSV file and there is Date column but it has content date and time like follows;
24/02/2017 13:57:53
manageInstance.Date = DateTime.ParseExact(valuesInCsvLine[0], dateFormatString, CultureInfo.InvariantCulture);
So,how I get time only from this format.I am doing C# programming.If anyone know,please help me.I am newer to this language.
You can parse your String as DateTime like
var text = "24/02/2017 13:57:53";
var dateTime = DateTime.Parse(text);
And then you can access the time like
var time = dateTime.TimeOfDay;
You can get time like var timeOnly = DateTime.Now.TimeOfDay;.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a C# program that communicates with MySql database and I want to write current time to database column defined as TIME. Now, when I run my program the time that has been written is for example 00:00:19 and not for example 19:34:00. Why this happens and how can I solve this?
Thanks in advance
SOLUTION
This solved the problem:
DateTime.Now.ToString("yyyyMMddHHmmss")
this because the format mysql : "yyyy-MM-dd hh:mm:ss"
check the format in you programme or try to insert a String like this "2016-23-08 13:00:00"
I think the problem caused by dateTimeVariable.ToString() method of your DateTime value.
To solve this problem use dateTimeVariable.ToString("s") to convert the DateTime to standard DateTime string.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a database field called "PIECE" which datatype is NUMERIC(11,0),
I must convert this field to a long-datatype.
This without any luck or succes, I'll keep getting the same error:
Wrong conversion...
I tried the next things:
(long)PIECE
long.Parse(PIECE.ToString().Trim())
But I'm still having the wrong conversion message,
is here someone who can help me?
This will do it:
var result = Convert.ToInt64(PIECE);
https://msdn.microsoft.com/en-us/library/0zahhahw(v=vs.110).aspx
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
How can I get the month from a date that is saved in data base.
int date = Convert.ToInt32(dr["ddate"].ToString());
Assuming that your date format is 'yyyy-MM-dd'
int month = DateTime.Parse(dr["ddate"].ToString()).Month;