473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Excel Date to PHP date

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
2/12/2011
6/10/2011

pl help
Nov 19 '11 #1
3 2634
dlite922
1,584 Expert 1GB
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));
  2.  
Nov 22 '11 #2
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
@dlite22,
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

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

Similar topics

1
by: Monica Roman | last post by:
Hello, help please. I have a little macro that copies the date from a date/time field to a memo field, BUT instead of going to the memo field it finds the first date/time field and tries to copy...
36
by: MLH | last post by:
Does Date = Date + 1 mean Date Statement equals Date Function plus 1? And if the answer is Yes, how much actual time is being added to the date function in this assignment?
0
by: Narshe | last post by:
I'm using the excel object from office web components in an asp.net webpage. I have 2 major issues. When a user hits enter on a cell, it moves cells. That's fine, 'cause that's how excel...
1
by: Me | last post by:
I need to get the past 5(x) months for certaing calculations. What I have is listed below: ######################################## my $year, $month_str, $month_int; foreach my $count...
2
by: ScardyBob | last post by:
Hello, I am having trouble importing data from an Excel Worksheet. When I try to import the data, everything works except certain columns that contain dates, where it replaces the date with a...
3
by: lyndac | last post by:
Hello! Last night a job to create a view using DATE(CURRENT DATE - 1 DAY) received the current days date instead the previous days date. Any one know why/how this can happen? The...
2
by: grego9 | last post by:
I have a problem in Excel 2000. I have written some VBA code that transfers data from the current excel workbook to a file called "Deal Input2.xls". Everything transfers ok apart from the date in...
1
by: dkyadav80 | last post by:
hi sir, I have following problem: code goes here: {code] 1. <html> 2. <body>
3
by: viditsinghal | last post by:
I need to write a C++ function that takes date as input and return day of the week as output. Can i get it somewhere where all the possiblibilies are covered. -Regards VS
4
code green
by: code green | last post by:
Within a stored procedure I am creating a table from an Excel spreadsheet /*Create tmp table from XLS*/ SELECT * INTO tmp_cons FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.