butlins
07-26-2007, 12:05 PM
I'm making the transition from ASP to PHP and am trying to get my head around the changes in syntax. I'm drawing a blank on converting this bit of server side VBScript (I'm now wishing I'd learned ASP/Javascript rather than ASP/VBScript, as much more of what I've done would be more easily portable):
<%
function ddmmyyyy(varDate)
ddmmyyyy = Day(DateValue(varDate)) & "/" & Month(DateValue(varDate)) & "/" & Year(DateValue(varDate))
end function
function mmddyyyy(varDate)
mmddyyyy = Month(DateValue(varDate)) & "/" & Day(DateValue(varDate)) & "/" & Year(DateValue(varDate))
end function
function yyyymmdd(varDate)
yyyymmdd = Year(DateValue(varDate)) & "/" & Month(DateValue(varDate)) & "/" & Day(DateValue(varDate))
end function
%>
I use it as a standalone function that allows me to pass the date entered in a form in dd/mm/yyyy format to an Access database in mm/dd/yyyy format (I've had problems in the past with Access getting confused between British and American date formats, and I've found this to be a reliable method of making sure that months and days don't flip).
I wanted to use something similar with PHP/MySQL so that the date passed from a form to the database is yyyy-mm-dd format, but I'm unfamiliar with MySQL datatypes and functions and PHP. Could anyone give me a hint?
<%
function ddmmyyyy(varDate)
ddmmyyyy = Day(DateValue(varDate)) & "/" & Month(DateValue(varDate)) & "/" & Year(DateValue(varDate))
end function
function mmddyyyy(varDate)
mmddyyyy = Month(DateValue(varDate)) & "/" & Day(DateValue(varDate)) & "/" & Year(DateValue(varDate))
end function
function yyyymmdd(varDate)
yyyymmdd = Year(DateValue(varDate)) & "/" & Month(DateValue(varDate)) & "/" & Day(DateValue(varDate))
end function
%>
I use it as a standalone function that allows me to pass the date entered in a form in dd/mm/yyyy format to an Access database in mm/dd/yyyy format (I've had problems in the past with Access getting confused between British and American date formats, and I've found this to be a reliable method of making sure that months and days don't flip).
I wanted to use something similar with PHP/MySQL so that the date passed from a form to the database is yyyy-mm-dd format, but I'm unfamiliar with MySQL datatypes and functions and PHP. Could anyone give me a hint?