Home > DeveloperSection > Forums > Need output in dd/MM/yyyy format from table value pair
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    December-23-2013 2:45 AM

 C# C# 
Ratings:


 1 Reply(s)
 742  View(s)
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



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-23-2013 5:06 AM

Hi Ankita,

Remove 'formats' declaration

Instead, change like this in your c#,

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

Don't want to miss updates? Please click the below button!

Follow MindStick