pitn Posted November 3, 2006 Share Posted November 3, 2006 Hello,Can someone help me?The input (webform) is a date like the following example (dd-mm-yyyy):$date = $_POST['date']; // for example $date contains 08-12-2006How can I extract the day, month ans year seperately?$day = ??? // what is the code to get the day (08) in the variable $day?$month = ??? // what is the code to get the month (12) in the variable $month?$year = ??? // what is the code to get the year (2006) in the variable $year?Many Tx! Quote Link to comment Share on other sites More sharing options...
marcus Posted November 3, 2006 Share Posted November 3, 2006 you could always just doon your form make like the date:[code]$date = date("d/m/y");[/code]then when grabbing it[code]$date = $_POST[date]; //getting posted[/code]then to get each field[code]$d1 = explode("/",$date);//or explode("/",$_POST[date]);[/code]then:[code]$day = $d1[1];$month = $d1[2];$year = $d1[3];[/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted November 3, 2006 Share Posted November 3, 2006 one method:[code]<?php$date = $_POST['date']; // for example $date contains 08-12-2006echo $day = substr($date,0,2); // 08echo $month = substr($date,3,2); // 12echo $year = substr($date,6,4); // 2006?>[/code] Quote Link to comment Share on other sites More sharing options...
pitn Posted November 3, 2006 Author Share Posted November 3, 2006 mgallforever and alpine, it worked !! perfect !! Thank you both ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.