显示日期为DD / MM / YYYY格式。 [英] Display date as DD/MM/YYYY format.

查看:237
本文介绍了显示日期为DD / MM / YYYY格式。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



每个人的美好的一天............



我有一个注册页面来创建用户。在这里它有发布日期和用户访问应用程序的到期日期。



我已设置,发布日期将是系统日期,对于到期日期,管理员将为用户选择它。



对于到期日,我有一个带有Ajax Calendar Extender的文本框。 ...当我点击提交时,到期日存储在数据库中为11/30/2012



但我的要求是.....



我希望将日期显示为dd / MM / yyyy格式使用标签...我使用过LABEL。



这是我的代码....请帮忙。



Dear Friends,

Good Day to every one of you............

I have a registration page to create the users..In this it has Issue date and Expiry date of user accessing the application.

I have set, Issue date will be the system date and for Expiry date administrator will choose it for the user.

For Expiry date I have a textbox with Ajax Calendar Extender....when i click on submit the expiry date is storing in database as 11/30/2012

But my requirement is.....

I want to display date as dd/MM/yyyy Format using label...I have used LABEL.

This is my code....Please help.

protected void Page_Load(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(_connString);
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "select datediff(dd,getdate(),ExpiryDate) as Edays, CONVERT(varchar, expirydate, 101) as ExpiryDates from dbo.UserAccounts where UserName='" + Session["UserName"].ToString() + "'";


        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {

            


               // lblExpiryDisplay.Text = DateTime.Parse(reader["ExpiryDates"].ToString()).ToString("dd/MM/yyyy");

                lblExpiryDisplay.Text = "Your Password will Expire on " + reader["ExpiryDates"].ToString() + " , and the Left Over days are " + reader["Edays"].ToString();


            }

           
        }
        con.Close();
        }

推荐答案

Quote:

lblExpiryDisplay.Text =你的密码将在+ reader [ExpiryDates]上过期.ToString()+和Left Over days是+ reader [Edays]。ToString();

lblExpiryDisplay.Text = "Your Password will Expire on " + reader["ExpiryDates"].ToString() + " , and the Left Over days are " + reader["Edays"].ToString();





试试这个:



Try this:

lblExpiryDisplay.Text = "Your Password will Expire on " + Convert.ToDateTime(reader["ExpiryDates"]).ToString("dd/MM/yyyy") + " , and the Left Over days are " + reader["Edays"].ToString();


以dd / MM / yyyy格式获取日期使用

To get date in dd/MM/yyyy format use
CONVERT(VARCHAR,expirydate,103)

在您的查询中



参考

如何格式化datetime& Sql Server中的日期 [ ^ ]


尝试下面的一个



CONVERT( VARCHAR,有效期,103)



语法:转换(数据类型,列名,样式编号)



ex:



在上面的语法中您可以指定您的样式编号。



样式编号是有效期从1到9,100到110,120到126



根据您的预期输出您可以传递时尚的数字。
Try the below one

CONVERT(VARCHAR ,expiry date ,103)

syntax: convert(datatype ,column-name,style number)

ex:

in the above syntax you can specify your style number.

style numbers are valid from 1 to 9 , 100 to 110, 120 to 126

based on your expected output you can pass the stylish number.


这篇关于显示日期为DD / MM / YYYY格式。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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