1

This code gets the date from the table to show in a table for the user

using System; 
using System.Data; 
using System.Configuration; 
using System.Web; 
using System.Web.Security; 
using System.Collections; 
using System.Collections.Generic;
using System.Text;

namespace Form 
{
    public class RelUso
    {
        public DateTime Date { get; set; }
    }
    public RelUso()
    {
        atribuiValores(row);
    }
    public RelUso(DataRow row)
    {
        assignValues(row);
    }
    protected void assignValues(DataRow row)
    {
        this.Data = Convert.ToDateTime(row["Date"]);
    }
}    

It gets the date how it is in the database yyyy-mm-dd hh:mm:ss. Can I do some method in the DateTime to change the formatting of the date to dd/mm/yyyy hh:mm:ss

PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68

2 Answers2

4

You can convert the DateTime structure to string using the following code:

var dt = DateTime.Now;
string str = dt.ToString("yyyy-MM-dd hh:mm:ss"); //(For month use caps 'MM')
mhan0125
  • 604
  • 1
  • 11
  • 33
2

Use

Convert.ToDateTime(row["Date"]).ToString("dd/MM/yyyy HH:mm:ss")
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
MyB
  • 199
  • 4