Click here to Skip to main content
12,068,141 members (51,734 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET formating
this Code Retrieve Date From SQL Database

LblExpirydate.Text = dataReader(0).ToString()

output : 01/05/2013 12:00:00 AM

i want to change format to (01/05/2013)
Posted 30-Mar-13 0:06am
Comments
Neetesh Agarwal 30-Mar-13 5:10am
   
You can try Substring()
Neetesh Agarwal 30-Mar-13 5:12am
   
dataReader(0).Substring(0,10)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

LblExpirydate.Text = dataReader(0).ToString("d")
  Permalink  
Comments
hany1002 30-Mar-13 5:23am
   
it return me this error in the same line (LblExpirydate.Text = dataReader(0).ToString("d"))

Error : Conversion From Sting "d" to 'integer' is not valid


connectionString = ConfigurationManager.ConnectionStrings("conString").ToString
connection = New SqlConnection(connectionString)
connection.Open()
command = New SqlCommand("SELECT Max(Expirydate) FROM Act WHERE Skey = '" & Request.QueryString("ID") & "'", connection)
dataReader = command.ExecuteReader
dataReader.Read()
LblExpirydate.Text = dataReader(0).ToString("d")
connection.Close()


sql database

ActID int Unchecked
Skey nvarchar(100) Checked
Expirydate date Checked
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

LblExpirydate.Text = dataReader(0).ToString("dd-MM-yyyy")
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

it return me this error in the same line (LblExpirydate.Text = dataReader(0).ToString("d"))

Error : Conversion From Sting "d" to 'integer' is not valid


connectionString = ConfigurationManager.ConnectionStrings("conString").ToString
        connection = New SqlConnection(connectionString)
        connection.Open()
        command = New SqlCommand("SELECT Max(Expirydate) FROM Act WHERE Skey = '" & Request.QueryString("ID") & "'", connection)
        dataReader = command.ExecuteReader
        dataReader.Read()
        LblExpirydate.Text = dataReader(0).ToString("d")
        connection.Close()


sql database

ActID int Unchecked
Skey nvarchar(100) Checked
Expirydate date Checked
  Permalink  
Comments
Neetesh Agarwal 30-Mar-13 5:24am
   
dataReader(0).Substring(0,10)
hany1002 30-Mar-13 5:28am
   
Same error

Notes :

sql database

ActID int Unchecked
Skey nvarchar(100) Checked
Expirydate date Checked
hany1002 30-Mar-13 5:29am
   
Error : Public member 'Substring' on type 'Date' not found.
Ayush Nautiyal 17-Oct-14 6:59am
   
how to convert 05/01/2014 to 5th Jan,14
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi!!! try this
query


SELECT FORMAT ( GETDATE(), 'DD/MM/YYYY', 'en-US' ) AS DateConvert;

or use like this in asp.net c#

string timeString = "30/03/2013 13:30:00.000";
IFormatProvider culture = new CultureInfo("en-US", true); 
DateTime dateVal = DateTime.ParseExact(timeString, "dd/MM/yyyy", culture);
  Permalink  
v2
Comments
hany1002 30-Mar-13 5:45am
   
that is my code how can i change it

connectionString = ConfigurationManager.ConnectionStrings("conString").ToString
connection = New SqlConnection(connectionString)
connection.Open()
command = New SqlCommand("SELECT Max(Expirydate) FROM Act WHERE Skey = '" & Request.QueryString("ID") & "'", connection)
dataReader = command.ExecuteReader
dataReader.Read()
LblExpirydate.Text = dataReader(0).ToString("d")
connection.Close()
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Solution :


LblExpirydate.Text = String.Format("{0:dd/MM/yyyy}", dataReader(0))
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

Use the query Select Convert(DateField,VarChar,103) from TableName
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 16 May 2014
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100