formmating dates?
am 11.11.2007 13:25:41 von mantrid
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?
Re: formmating dates?
am 11.11.2007 13:49:03 von AnrDaemon
Greetings, mantrid.
In reply to Your message dated Sunday, November 11, 2007, 15:25:41,
> 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?
strptime may help You.
But be careful about original date format.
--
Sincerely Yours, AnrDaemon
Re: formmating dates?
am 11.11.2007 14:39:56 von mantrid
"AnrDaemon" wrote in message
news:1709611300.20071111154903@freemail.ru...
> Greetings, mantrid.
> In reply to Your message dated Sunday, November 11, 2007, 15:25:41,
>
> > 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?
>
> strptime may help You.
> But be careful about original date format.
>
>
> --
> Sincerely Yours, AnrDaemon
>
Thanks
but not using version 5 so not supported
Ian
Re: formmating dates?
am 11.11.2007 16:15:48 von mantrid
"mantrid" wrote 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
>
> 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?
>
>
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.
Re: formmating dates?
am 11.11.2007 17:09:46 von zeldorblat
On Nov 11, 10:15 am, "mantrid" wrote:
> "mantrid" wrote 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
>
> > 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?
>
> 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));
Re: formmating dates?
am 11.11.2007 22:27:25 von AnrDaemon
Greetings, mantrid.
In reply to Your message dated Sunday, November 11, 2007, 16:39:56,
> 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
Re: formmating dates?
am 12.11.2007 01:21:19 von mantrid
Thanks will give it a go
Ian
"ZeldorBlat" wrote in message
news:1194797386.921008.62810@d55g2000hsg.googlegroups.com...
> On Nov 11, 10:15 am, "mantrid" wrote:
> > "mantrid" wrote 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
> >
> > > 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?
> >
> > 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));
>
Re: formmating dates?
am 13.11.2007 18:47:37 von Toby A Inkster
ZeldorBlat wrote:
> 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/viewvc/demiblog/trunk/bl og/includes/i18n.php?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/08/19/trivial-encoder/