Convert DateTime for MySQL using C#

后端 未结 4 1484
悲&欢浪女
悲&欢浪女 2020-11-27 16:32

I want to change the DateTime for MySQL in C#.

My MySQL database only accept this format 1976-04-09 22:10:00.

In C# have a string who have a dat

4条回答
  •  死守一世寂寞
    2020-11-27 17:24

    This works for me:

    1.Extract date from oracle data base and pass it to variable

     string lDat_otp = "";
    
      if (rw_mat["dat_otp"].ToString().Length <= 0)
      {
          lDat_otp = "";
      }
      else
      {
          lDat_otp = rw_mat["dat_otp"].ToString();
      }
    

    2.Conversion to mysql format

    DateTime dateValue = DateTime.Parse(lDat_otp);
    string formatForMySql = dateValue.ToString("yyyy-MM-dd HH:mm");
    

    3.Pass formatForMySql variable to procedure or to something else

提交回复
热议问题