如何在插入表时将任何日期格式转换为数据库日期格式 [英] How to convert any date format into database date format while inserting into table

查看:243
本文介绍了如何在插入表时将任何日期格式转换为数据库日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我使用一个文本框输入日期。我的问题是有人正在输入dd-mm-yyyy(或)mm-dd-yyyy(或)dd / mm / yyyy这样他们在文本框中键入的任何格式但是我应该保存在表格中我能实现这个.... 。



Mote: - 对于那个文本框我带了ajax日历来选择日期(这里我的问题是如果他们没有从日历中选择,如果他们进入意味着我应该怎么做转换为日期,如果它是日期格式意味着)

解决方案

尝试使用它:



示例



  string  inputDate =   03/12/2012; 

DateTime dt = DateTime.MinValue;
dt = DateTime.Parse(inputDate);

string formatDate = String .Format( {0:MMM d,yyyy},dt); // 设置如何设置ajax日历的格式







希望它有所帮助! :)


  1 )DateTime.Parse( 您的日期,System.Globalization.CultureInfo.InvariantCulture); 

2 )DateTime.ParseExact( 您的日期 dd-MMM-yyyy,System.Globalization .CultureInfo.InvariantCulture);


Actually i am using one text box to enter date. my problem is some one is typing dd-mm-yyyy (or) mm-dd-yyyy (or) dd/mm/yyyy like this any format they type in textbox but i should save in table can i Achieve this.....

Mote:-for that text box i taken ajax calender to select date(Here my problem is if they not selected from the calender if they entered means how should i convert into date if it is in date format means)

解决方案

Hi, try to use this:

Example

string inputDate = "03/12/2012";

DateTime dt = DateTime.MinValue;
dt = DateTime.Parse(inputDate);

string formatDate = String.Format("{0:MMM d, yyyy}", dt); //Set on how the format of ajax calendar has been set




Hope it helps! :)


1) DateTime.Parse("your date", System.Globalization.CultureInfo.InvariantCulture);

2) DateTime.ParseExact("your date", "dd-MMM-yyyy",System.Globalization.CultureInfo.InvariantCulture);


这篇关于如何在插入表时将任何日期格式转换为数据库日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆