Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2007, 12:05 PM   PM User | #1
butlins
Regular Coder

 
Join Date: Aug 2006
Location: Cardiff, UK
Posts: 141
Thanks: 15
Thanked 2 Times in 2 Posts
butlins is an unknown quantity at this point
Date function conversion from VBScript

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):
Code:
<%
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?
__________________
If anyone asks my boss, this counts as work, okay?
butlins is offline   Reply With Quote
Old 07-26-2007, 01:58 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
How are you reading the date from your form?

If it's by using three input fields for year,month and day , you can easily append the result of the submited form in PHP as

Code:
$date = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
where year,month and day are the names of the input fields, and should have the proper values in it.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 07-27-2007, 02:29 PM   PM User | #3
butlins
Regular Coder

 
Join Date: Aug 2006
Location: Cardiff, UK
Posts: 141
Thanks: 15
Thanked 2 Times in 2 Posts
butlins is an unknown quantity at this point
Hadn't thought of that - it's currently as a single field - but it's worth my having a look at that, thanks. The nice thing about my little VBScript is that it's portable - you can can feed any date to it, and it'll return the formatted version. So (forgive me for the VBScript in the PHP forum) I can use it to format text on a page

Code:
<%= ddmmyyyy(rsContent.Fields.Item("DateStart").Value%>
displays DateStart in dd/mm/yyyy
Code:
<input name="DateStart" type="text" id="DateStart" title="Enter the start date" value="<%= ddmmyyyy(rsCourse.Fields.Item("DateStart").Value) %>" size="12" maxlength="12" />
puts the DateStart value in ddmmyyyy in a field for an update form in my CMS, and
Code:
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 135, 1, -1, MM_IIF(mmddyyyy(Request.Form("DateStart")), mmddyyyy(Request.Form("DateStart")), null)) ' adDBTimeStamp
Inserts the date into the database in mm/dd/yyyy format (using the Dreamweaver update server behaviour). It's just nice to be able to use the same function each time.
__________________
If anyone asks my boss, this counts as work, okay?
butlins is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:22 PM.


Advertisement
Log in to turn off these ads.