Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Changing Date Format

Changing Date Format

Scheduled Pinned Locked Moved ASP.NET
databasehelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    munklefish
    wrote on last edited by
    #1

    Hi, Due to various limitation i need to be able to change the format of dates in a SQl2005 db from DD/MM/YYYY to YYYY/MM/DD. Ideally this should be a stored proceedure. Any help would as always be very greatfully received. Thanks in advance. Phill

    T B 2 Replies Last reply
    0
    • M munklefish

      Hi, Due to various limitation i need to be able to change the format of dates in a SQl2005 db from DD/MM/YYYY to YYYY/MM/DD. Ideally this should be a stored proceedure. Any help would as always be very greatfully received. Thanks in advance. Phill

      T Offline
      T Offline
      Taurian110
      wrote on last edited by
      #2

      Are you talking about updating the date format the way it is stored in the database? Or when you are retrieving it? Also what is the data type of your date column is it varchar or DateTime? If you just want to change the date format when retrieving the data then something like this will work:

      SELECT
               Convert(varchar, DATEPART(yyyy, UploadDate)) + '/' + 
               Convert(varchar, DATEPART(mm, UploadDate)) + '/' + 
               Convert(varchar, DATEPART(dd, UploadDate)) as MyNewFormat
      FROM
               dbo.[MytableName]
      

      *Change the MytableName to your table and UploadeDate to your column name hth

      1 Reply Last reply
      0
      • M munklefish

        Hi, Due to various limitation i need to be able to change the format of dates in a SQl2005 db from DD/MM/YYYY to YYYY/MM/DD. Ideally this should be a stored proceedure. Any help would as always be very greatfully received. Thanks in advance. Phill

        B Offline
        B Offline
        Blue_Boy
        wrote on last edited by
        #3

        select convert(varchar,columnname,111) from myTable


        I Love T-SQL

        M 1 Reply Last reply
        0
        • B Blue_Boy

          select convert(varchar,columnname,111) from myTable


          I Love T-SQL

          M Offline
          M Offline
          munklefish
          wrote on last edited by
          #4

          Its throwing up an OleDbException: 'Undefined function 'Convert' in expression.' Any ideas?

          B 1 Reply Last reply
          0
          • M munklefish

            Its throwing up an OleDbException: 'Undefined function 'Convert' in expression.' Any ideas?

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #5

            Are you using SQL Server database or MS Access database?


            I Love T-SQL

            M 1 Reply Last reply
            0
            • B Blue_Boy

              Are you using SQL Server database or MS Access database?


              I Love T-SQL

              M Offline
              M Offline
              munklefish
              wrote on last edited by
              #6

              SQL 2005 Although im trying to do the convert on when uploading an Excel sheet to SQL2005 using BulkCopy. See below: protected void Page_Load(object sender, EventArgs e) { // Connection String to Excel Workbook //string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BLAH\qs_upload.xls;Extended Properties=""Excel 8.0;HDR=YES;"""; string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BLAH\qs_upload.xls;Extended Properties=""Excel 8.0;HDR=YES;"""; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand("Select * FROM [quality_standard$]", connection); //OleDbCommand command = new OleDbCommand("Select qs_Id, qs_Organisation, Convert(varchar,qs_Start,111), qs_End FROM [quality_standard$]", connection); connection.Open(); // Create DbDataReader to Data Worksheet using (OleDbDataReader dr = command.ExecuteReader()) { // SQL Server Connection String string sqlConnectionString = "REMOVED" // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "tbl_QualityStandard"; bulkCopy.WriteToServer(dr); } } } }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups