Connecting Tech Pros Worldwide Help | Site Map

formmating dates?

mantrid
Guest
 
Posts: n/a
#1: Nov 11 '07
Im reading a csv file with php and getting a date in the form 30/09/07

Which I am trying to insert into a mysql table which has the field formatted
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?


AnrDaemon
Guest
 
Posts: n/a
#2: Nov 11 '07

re: formmating dates?


Greetings, mantrid.
In reply to Your message dated Sunday, November 11, 2007, 15:25:41,
Quote:
Im reading a csv file with php and getting a date in the form 30/09/07
Quote:
Which I am trying to insert into a mysql table which has the field formatted
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?
strptime may help You.
But be careful about original date format.


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

mantrid
Guest
 
Posts: n/a
#3: Nov 11 '07

re: formmating dates?



"AnrDaemon" <anrdaemon@freemail.ruwrote in message
news:1709611300.20071111154903@freemail.ru...
Quote:
Greetings, mantrid.
In reply to Your message dated Sunday, November 11, 2007, 15:25:41,
>
Quote:
Im reading a csv file with php and getting a date in the form 30/09/07
>
Quote:
Which I am trying to insert into a mysql table which has the field
formatted
Quote:
Quote:
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?
>
strptime may help You.
But be careful about original date format.
>
>
--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>
>

Thanks
but not using version 5 so not supported
Ian


mantrid
Guest
 
Posts: n/a
#4: Nov 11 '07

re: formmating dates?



"mantrid" <ian.dandav@virgin.netwrote in message
news:9xCZi.21578$6v.8195@newsfe2-gui.ntli.net...
Quote:
Im reading a csv file with php and getting a date in the form 30/09/07
>
Which I am trying to insert into a mysql table which has the field
formatted
Quote:
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?
>
>
I was able to work around the problem using

$datebits = explode("/", $dateandtime);
$dateandtime = date('Y-m-d
H:i:s',mktime(00,00,00,$datebits[1],$datebits[0],$datebits[2]));

However, if there is a simple single function I can use, or if anyone knows
a better way please let me know as users may not use the dd/mm/yyy format
but could use something along the lines of dd-mm-yyyy or any other style.


ZeldorBlat
Guest
 
Posts: n/a
#5: Nov 11 '07

re: formmating dates?


On Nov 11, 10:15 am, "mantrid" <ian.dan...@virgin.netwrote:
Quote:
"mantrid" <ian.dan...@virgin.netwrote in message
>
news:9xCZi.21578$6v.8195@newsfe2-gui.ntli.net...Im reading a csv file with php and getting a date in the form 30/09/07
>
Quote:
Which I am trying to insert into a mysql table which has the field
formatted
Quote:
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?
>
I was able to work around the problem using
>
$datebits = explode("/", $dateandtime);
$dateandtime = date('Y-m-d
H:i:s',mktime(00,00,00,$datebits[1],$datebits[0],$datebits[2]));
>
However, if there is a simple single function I can use, or if anyone knows
a better way please let me know as users may not use the dd/mm/yyy format
but could use something along the lines of dd-mm-yyyy or any other style.
Use strtotime() and date():

date('Y-m-d', strtotime($dateandtime));

AnrDaemon
Guest
 
Posts: n/a
#6: Nov 11 '07

re: formmating dates?


Greetings, mantrid.
In reply to Your message dated Sunday, November 11, 2007, 16:39:56,
Quote:
Thanks
but not using version 5 so not supported
Welcome to reality.
http://www.php.net/index.php#2007-07-13-1


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

mantrid
Guest
 
Posts: n/a
#7: Nov 12 '07

re: formmating dates?


Thanks will give it a go
Ian


"ZeldorBlat" <zeldorblat@gmail.comwrote in message
news:1194797386.921008.62810@d55g2000hsg.googlegro ups.com...
Quote:
On Nov 11, 10:15 am, "mantrid" <ian.dan...@virgin.netwrote:
Quote:
"mantrid" <ian.dan...@virgin.netwrote in message

news:9xCZi.21578$6v.8195@newsfe2-gui.ntli.net...Im reading a csv file
with php and getting a date in the form 30/09/07
Quote:
Quote:
Quote:
Which I am trying to insert into a mysql table which has the field
formatted
Quote:
as yyyy-mm-dd hh:mm:ss
I cant get it to insert the field remains blank
How do I do this?
I was able to work around the problem using

$datebits = explode("/", $dateandtime);
$dateandtime = date('Y-m-d
H:i:s',mktime(00,00,00,$datebits[1],$datebits[0],$datebits[2]));

However, if there is a simple single function I can use, or if anyone
knows
Quote:
Quote:
a better way please let me know as users may not use the dd/mm/yyy
format
Quote:
Quote:
but could use something along the lines of dd-mm-yyyy or any other
style.
Quote:
>
Use strtotime() and date():
>
date('Y-m-d', strtotime($dateandtime));
>

Toby A Inkster
Guest
 
Posts: n/a
#8: Nov 13 '07

re: formmating dates?


ZeldorBlat wrote:
Quote:
Use strtotime() and date():
date('Y-m-d', strtotime($dateandtime));
If you know that DMY dates are more likely than MDY dates, strtotime() can
be problematic. In the case of an ambiguous date (e.g. 01/02/08) it will
always assume MDY, which will be wrong in the majority of cases (less than
10% of the world uses MDY dates).

I recommend taking a look at my strtotime_i18n() function which takes two
parameters: the date string, plus a hint of the form 'dmy', 'mdy' or
'ymd':

http://demiblog.svn.sourceforge.net/...hp?view=markup

Something like '01/28/2008' will always be parsed as 28 Jan 2008 as there
is no 28th month, but in ambiguous cases, it should help you out. If you
want to use it, you may want to rewrite the small part at the top of the
function which checks if $assumption==NULL. It relies on some other
functions and objects in my project, which you're less likely to want to
use.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 7 days, 26 min.]

TrivialEncoder/0.2
http://tobyinkster.co.uk/blog/2007/0...ivial-encoder/
Closed Thread