Jump to content

extract character from variable


pitn

Recommended Posts

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-2006

How 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!
Link to comment
https://forums.phpfreaks.com/topic/26080-extract-character-from-variable/
Share on other sites

you could always just do

on 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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.