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 8:50am
Ali_1001.3K
Edited 21-Feb-13 8: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 Sergey Alexandrovich Kryukov 474
1 Maciej Los 375
2 OriginalGriff 263
3 CPallini 214
4 Peter Leow 200
0 OriginalGriff 6,152
1 Sergey Alexandrovich Kryukov 5,312
2 Maciej Los 3,279
3 Peter Leow 3,184
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.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