|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 You. But be careful about original date format. -- Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"AnrDaemon" <anrdaemon@freemail.ru> 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 You. > But be careful about original date format. > > > -- > Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru> > Thanks but not using version 5 so not supported Ian |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"mantrid" <ian.dandav@virgin.net> 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. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Nov 11, 10:15 am, "mantrid" <ian.dan...@virgin.net> wrote:
> "mantrid" <ian.dan...@virgin.net> 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)); |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 <anrdaemon@freemail.ru> |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Thanks will give it a go
Ian "ZeldorBlat" <zeldorblat@gmail.com> wrote in message news:1194797386.921008.62810@d55g2000hsg.googlegro ups.com... > On Nov 11, 10:15 am, "mantrid" <ian.dan...@virgin.net> wrote: > > "mantrid" <ian.dan...@virgin.net> 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)); > |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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/...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 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/ |
|
![]() |
| Outils de la discussion | |
|
|