NEED OUTPUT IN DD/MM/YYYY FORMAT FROM TABLE VALUE PAIR

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
C# 
C#
 1077  View(s)
Ratings:
Rate this:

Here is my code for passing table value pair to stored procedure. DOJ field is DateTime and in SP, DOJ field is date. Both are compatible. Output is like dd/MM/yyyy.

If DOJ field is DateTime and in SP, DOJ field is DateTime2(3), o/p is dd/MM/yyyy hh:mm:ss But I need o/p to be dd/MM/yyyy. How should i write the code ?

dt1.Columns.Add("DOJ", typeof(System.DateTime));

DataRow dr1 = dt1.NewRow();

dr1["DOJ"] = DateTime.ParseExact("02/03/2001", formats, us, DateTimeStyles.None);

// dr1["DOJ1"] = "12/13/2001";   if i use  this one it works .

dt1.Rows.Add(dr1);    // Get DOJ as - 3/2/2001 12:00:00 AM

ds1.Tables.Add(dt1);

Here is my stored procedure code -

-- CREATE TYPE StateTbls7 AS TABLE

( StateID   VARCHAR(200)

, StateCode VARCHAR(200)

, StateName VARCHAR(200)

, DOJ      date           

)

ALTER PROCEDURE sp_Add_contact

    (

      @ds1 StateTbls7 readonly

    )

AS

    begin

              declare @DOJ       VARCHAR(200)

          select @DOJ = d1.DOJ   from @ds1   d1

              select  @DOJ as 'a1'

    end

return

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Need output in dd/MM/yyyy format from table value pair

    Hi Ankita,


    Remove 'formats' declaration

    Instead, change like this in your c#,

    dr1["DOJ"] = DateTime.ParseExact("02/03/2001", us, DateTimeStyles.None).ToString("d");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!