关于将SQL参数作为datetime传递 [英] about passing sql parameters as datetime

查看:96
本文介绍了关于将SQL参数作为datetime传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好法国人,我有一个同样的问题,我现在将日期分为月,日,年,并且它们都是字符串,现在我想要做的是将其连接起来,以便格式看起来像11/4/2011但是当我串联时,我无法在字符串后附加/?如何执行此类任务,请提供帮助
关于bishnu karki

hello frens i have the same question, i now broke the date into month,day,year and all of them are in string, now what i wanted to do is concatenate it so that the format looks like 11/4/2011 but when i concatenated, i could not append / with string? how to perform such task please help
with regards bishnu karki

推荐答案

不知道为什么要将Date拆分为Month,Day和Year,然后又想将其拆分.

而是使用以下语法.
Not sure why you are splitting your Date into Month, Day and Year and then again want to concatenate it.

Instead use below syntax.
string myDate = System.DateTime.Now.ToString("MM/dd/yyyy");


当所有字符串都为字符串形式时,问题出在哪里? :
what is the problem when all are in string form u can simply do as:
string a = "12";
        string b = "12";
        string c= "12";
        string d = a+"/"+b+"/"+c;


字符串d仅具有字符串形式的完整日期


string d will have complete date in string form only


假设您有3个下拉列表,您可以尝试类似:

Assuming you have 3 dropdown for date, you can try something like :

int day = 0;
int month = 0;
int year = 0;
day = Convert.ToInt32(dropdownday.SelectedValue.ToString());
month = Convert.ToInt32(dropdownMonth.SelectedValue.ToString());
year = Convert.ToInt32(dropdownYear.SelectedValue.ToString());

System.DateTime newdate = new System.DateTime(year, month, day);
newdate.ToString("d");
//newdate can be passed as datetime parameter;


这篇关于关于将SQL参数作为datetime传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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