PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > formmating dates?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
formmating dates?

Réponse
 
LinkBack Outils de la discussion
Vieux 11/11/2007, 13h25   #1
mantrid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut formmating dates?

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?


  Réponse avec citation
Vieux 11/11/2007, 13h49   #2
AnrDaemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?

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>

  Réponse avec citation
Vieux 11/11/2007, 14h39   #3
mantrid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?


"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


  Réponse avec citation
Vieux 11/11/2007, 16h15   #4
mantrid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?


"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.


  Réponse avec citation
Vieux 11/11/2007, 17h09   #5
ZeldorBlat
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?

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));

  Réponse avec citation
Vieux 11/11/2007, 22h27   #6
AnrDaemon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?

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>

  Réponse avec citation
Vieux 12/11/2007, 01h21   #7
mantrid
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?

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));
>



  Réponse avec citation
Vieux 13/11/2007, 18h47   #8
Toby A Inkster
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: formmating dates?

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/
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14309 seconds with 16 queries