date conversion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

date conversion

Post by valen53 »

i use sql2000, so the date format i query are apr, 1 2003, 12:00
but i want split it to 04/01/2003 ...
but i can't change the date format from apr to 04..
below is my code.. anyone can help me ??
thank u

list ($mon,$day,$year, $time) = split (' ', $Itemrow[StartDate]) ;
$repairDate = date('m/d/Y', mktime(0,0,0, "$mon,$day,$year"));
Malder
Forum Newbie
Posts: 13
Joined: Wed Mar 19, 2003 11:09 pm

Post by Malder »

try explode instead of split
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post by valen53 »

Malder wrote:try explode instead of split
actually not split problem , i just split the date. but apr is string ..
when use mktime (0,0,0 int,int,int ) so i can't convert it string to int..

list ($mon,$day,$year, $time) = explode(' ', $Itemrow[StartDate]) ;
$repairDate = date('m/d/Y', mktime(0,0,0, $mon,$day,$year));
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

oracle has a date conversion function, don't know whether you sql has something similar:

to_char(datefield,'DD-MM-YYYY');


maybe check on that so you don't have to parse the date
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you can't adjust the date in the database (which would be the best solution) then you should look into strtotime():
http://www.php.net/manual/en/function.strtotime.php

Mac
Post Reply