By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Excel Date to PHP date

P: 7
for converting mm/dd/yy to yyyy-mm-dd, I used this code
list($d, $m, $y) = preg_split('/\//', $normal_date);

$mydate = sprintf('%4d%02d%02d', $y, $m, $d);
print $mydate;

following date is not converted
10/20/2011 ( that is to say, if both month and date are 2 digts)

whereas rest of the excel dates are being converted

pl help
Nov 19 '11 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,584
use mktime function to convert to time. Then give that to the date function choosing the format that you want.

Expand|Select|Wrap|Line Numbers
  1. $mydate = date('Y-m-D',mktime(0,0,0,$d,$m,$y));
Nov 22 '11 #2

P: 43
For me it's working fine.

Also, I agree with "dlite22", you should use PHP provided functions extensively to avoid any bugs and all.

You can also thik of getting rid of regex preg_split() it slows down the execution. Use some string based functions to split it up
Nov 23 '11 #3

P: 43
I think it should be small d in place of capital D in date()

Expand|Select|Wrap|Line Numbers
  1. $mydate = date('Y-m-d',mktime(0,0,0,$d,$m,$y));
Nov 23 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.