Page 1 of 1

dates

Posted: Thu Jul 14, 2005 7:21 am
by gurjit
hi all,

i have a random entry of the way people have entered the month of a date, for example

21 february

has been entered as:
21/feb
21/FEB
21/Feb
21/february
21/February
21/FEBRUARY
21/2
21/02

I tried to run this script with
21/feb and it gave the output:

"2004-12-21" why?
this is my script


Code: Select all

<?php
$dd = '21/feb';
$pieces = explode("/", $dd);

$d = $pieces[0];
$m = $pieces[1];
$y = date("Y");


$term_started = date('Y-m-d',mktime(0,0,0,$m,$d,$y));



echo $term_started;
?>

Posted: Thu Jul 14, 2005 8:10 am
by onion2k
I doubt mktime() would like "feb" or "february" as an argument. Integers only. Try looking at strtotime() instead.

Posted: Thu Jul 14, 2005 8:57 am
by gurjit
tried this and it gave me "2026-07-29"

Code: Select all

<?php

$dd = '21/feb';
$pieces = explode("/", $dd);

$d = $pieces[0];
$m = $pieces[1];
$y = date("Y");

$ths = "$y-$m-$d";
$term_started2 = date("Y-m-d",strtotime($ths));

echo $term_started2;
?>

Posted: Thu Jul 14, 2005 1:00 pm
by timvw
The manual says that strtotime will accept the following formats: http://www.gnu.org/software/tar/manual/ ... tar_7.html


Thus the following code should work:

Code: Select all

$dd = '21/feb';
$pieces = explode("/", $dd);
 
$d = $pieces[0];
$m = $pieces[1];
$y = date("Y");
 
$ths = "$d $m $y";
$term_started2 = date("Y-m-d",strtotime($ths));