Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find a matching quote character for the character '''

Tags:

c#

I have the following code:

 examdate = Convert.ToDateTime(ttd.DateCreated).ToString("MMM dd yy");

and it returns Jun 27 18

but I need the following output

Jun 27 '18

so I changed my code to

 examdate = Convert.ToDateTime(ttd.DateCreated).ToString("MMM dd 'yy");

and it threw up an error: Cannot find a matching quote character for the character '''.

like image 955
Venkat Avatar asked Jan 02 '23 05:01

Venkat


1 Answers

You just have to escape the single quote (') inside of the ToString() call.

Simple example:

using System;

    public class Program
    {
        public static void Main()
        {
            Console.WriteLine(DateTime.Now.ToString("MMM dd \\'yy"));
        }
    }

Result:

Jun 27 '18

Fiddle Demo

like image 175
Shar1er80 Avatar answered Jan 25 '23 23:01

Shar1er80