Convert Variables and Strings to Date-Time Format
source link: https://www.codesd.com/item/convert-variables-and-strings-to-date-time-format.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Convert Variables and Strings to Date-Time Format
I currently have the following variables and formatted data:
- Scheduling_StartDate_Month = 10
- Scheduling_StartDate_Day = 1
- Scheduling_StartDate_Year = 2012
- Scheduling_StartTime = 3:00 PM
I need to combine them into one variable 'schedstart' of type 'datetime' to insert into my database, and I'm completely lost. I have tried to research the issues, and found suggestions to use mktime() or sttodate() but I couldn't find any reliable syntax guidelines.
How do I combine those variables using PHP?
You can consider concatenating in a proper format on the PHP:
<?php
$dateString = $Scheduling_StartDate_Month."/".$Scheduling_StartDate_Day."/".$Scheduling_StartDate_Year." ".$Scheduling_StartTime;
$result = mysql_query("SELECT STR_TO_DATE('".$dateString."', '%m/%d/%Y %h:%i %p')");
?>
Related Articles
How to analyze and convert DateTime to RFC 822 date-time format?
CAST () or CONVERT () do not change the date-time format to a string in SQL Server 2008
Try to convert a string to date-time format in vb.net 2005
How to convert two different strings to date format and find their differences in JSP / JAVA
Convert long date strings in Excel to a sortable date / time format
How to convert a date field to date-time format? SQL 2008
Convert to date-time format for pandas?
Merge two columns into a single column and format the content to form a specific date-time format in Hive?
How to convert nanoseconds of uptime to a readable date time format
How to update / change the system date time format in the regional and language options of the control panel using the code?
How can I change the date time formats in Perl?
If I have a date time format, do I need to display a single time?
Implement LINQ expressions to SQL for a database with a custom date / time format
Change the default date time format on a single database in SQL Server
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK