Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: DateTime format
if (dtProcedureDocs != null)
                        {
                            DataTable dt = GetProcedureDocssDatatable();
                            string DocTitleID = lstofWF.Where(o => o.FName == "Document Title").Select(s => s.FID).FirstOrDefault().ToString();
                            string DocCatID = lstofWF.Where(o => o.FName == "Document Category").Select(s => s.FID).FirstOrDefault().ToString();
 
                            foreach (DataRow sRow in dtProcedureDocs.Rows)
                            {
                                DataRow dr = dt.NewRow();
                                dr["Name"] = sRow["Name"];
                                dr["Document Title"] = sRow[DocTitleID];
                                dr["Document Type"] = sRow[DocCatID];
                                dr["Owner"] = sRow["OwnerGuid"].ToString();
                                dr["Created By"] = sRow["CreatedByGuid"].ToString();
                                dr["Created Date"] = String.Format("{0:M/d/yyyy}", sRow["CreatedDate"].ToString());
                                dr["Modified By"] = sRow["ModifiedByGuid"].ToString();
                                dr["Current Version"] = sRow["OwnerGuid"].ToString();
 
                                objTemplatesHelper.InsertRowInDocumentTable(table, dr);
                            }
 
                        }
 
 private DataTable GetProcedureDocssDatatable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Document Title", typeof(string));
            dt.Columns.Add("Document Type", typeof(string));
            dt.Columns.Add("Owner", typeof(string));
            dt.Columns.Add("Created By", typeof(string));
            dt.Columns.Add("Created Date", typeof(string));
            dt.Columns.Add("Modified By", typeof(string));
            dt.Columns.Add("Current Version", typeof(string));
            return dt;
        }
 
Q1 The main things i added here, dtProcedureDocs was fetched from DB & I am exporting the values in MSWORD,the output is not giving me like that ["dd/mm/yyyy"]
 
---------------------------------------------------------------------------------------------
 
Q2 If I change the datatype of created date to date time like below,,,then how can i format in the above code?
 private DataTable GetProcedureDocssDatatable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Document Title", typeof(string));
            dt.Columns.Add("Document Type", typeof(string));
            dt.Columns.Add("Owner", typeof(string));
            dt.Columns.Add("Created By", typeof(string));
            dt.Columns.Add("Created Date", typeof(datetime));
            dt.Columns.Add("Modified By", typeof(string));
            dt.Columns.Add("Current Version", typeof(string));
            return dt;
        } 
Posted 21-Feb-13 9:50am
Ali_1001.3K
Edited 21-Feb-13 9:52am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Ali_100, start here: Data Types (C#)[^]. More here: Date Data Type[^]
 
Remember: Date is a date, string is a string!
 
If you want to store dates, you need to use date not string data type. Of course, you can always parse date from string, as is described here: http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx[^]...
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I did it by the link
Click
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 Sergey Alexandrovich Kryukov 170
4 PIEBALDconsult 160
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
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