Convert string to datetime value in LINQ

前端 未结 3 456
北恋
北恋 2020-12-20 01:42

Suppose I have a table storing a list of datetime (yyyyMMdd) in String format. How could I extract them and convert them into DateTime format dd/MM/yyyy ?

3条回答
  •  自闭症患者
    2020-12-20 02:41

    As already said, it's better to store date as date-type column in your DB, but if you want just to convert strings from one format to another, you can do this:

    db.tb1.Select(x => String.Format("{0}/{1}/{2}", x.Substring(6, 2), x.Substring(4, 2), x.Substring(0, 4))
    

提交回复
热议问题