Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    Cardiff, UK
    Posts
    141
    Thanks
    15
    Thanked 2 Times in 2 Posts

    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?

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Location
    Cardiff, UK
    Posts
    141
    Thanks
    15
    Thanked 2 Times in 2 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •