Each programming language has its own functions to convert date variables to strings. In some cases, you need to convert a date to a string variable to avoid a syntax error. The PHP, VB.NET and C# languages are online programming languages that allow you to create dynamic Web pages. Both VB.NET and C# use the "ToString" function to perform the conversion. PHP requires you to convert the string to a long date string.
- Skill level:
Other People Are Reading
Click the Windows "Start" button and type "visual studio" in the search text box. Press "Enter" to open the C# programming software.
Open your Web project, then open the code file for the C# form. Use the following code to create a date value, if you do not already have one:
DateTime mydate = new DateTime;
mydate = DateTime.Now;
Convert the date to a string. The following code changes the date created in Step 2 to a string:
string stringvar = string.Empty;
stringvar = mydate.ToString();
Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET Framework," then click "Visual Studio."
Open your VB.NET project and load the code file to set up the date-to-string conversion. Use the following code to create a date in VB.NET:
Dim myvar As DateTime
myvar = "2/1/2011"
Convert the date created in step to to a string. The following code performs the conversion in VB.NET:
Dim newvar As String
newvar = myvar.ToString()
Right-click the PHP file you want to edit and select "Open With." Double-click your PHP file editor in the list of programs.
Create a date variable, if you do not already have a variable set up in the PHP file. The following code shows you how to create a date in PHP:
$date = '1/1/2011';
Convert the date to a string. Use the following code to convert the date:
$newstring = date('l dS \o\f F Y h:i:s A', $date);
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for