Date Conversion

Date Conversion

am 18.08.2004 09:05:54 von Ng Hwee Hwee

------=_NextPart_000_0095_01C48534.DBF44970
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all,

can someone kindly point me to a resource that converts all kinds of =
possible date inputs into MySQL format of YYYY-MM-DD?

example of formats to be converted includes:

d/m/yy
d/m/yyyy
d/mm/yy
d/mm/yyy
dd/mm/yy
dd/mm/yyy
d/mmm/yy
d/mmm/yyyy
dd/mmm/yy
dd/mmm/yyyy

yy - 2 digit representation of year
yyyy - ful numeric representation of year
m - numeric representation of month, without leading zero
mm - numeric representation of month, with leading zero
mmm - short textual representation of month =20
d - day of month without leading zero
dd - day of month with leadin zero

thanx!

hwee
------=_NextPart_000_0095_01C48534.DBF44970--

Re: Date Conversion

am 18.08.2004 10:16:59 von Torsten Roehr

>"Ng Hwee Hwee" wrote in message
news:009801c484f1$d11c8af0$800101df@hweehwee...
>Hi all,
>
>can someone kindly point me to a resource that converts all kinds of
possible date inputs into MySQL format of YYYY-MM-DD?
>
>example of formats to be converted includes:
>
>d/m/yy
>d/m/yyyy
>d/mm/yy
>d/mm/yyy
>dd/mm/yy
>dd/mm/yyy
>d/mmm/yy
>d/mmm/yyyy
>dd/mmm/yy
>dd/mmm/yyyy
>
>yy - 2 digit representation of year
>yyyy - ful numeric representation of year
>m - numeric representation of month, without leading zero
>mm - numeric representation of month, with leading zero
>mmm - short textual representation of month
>d - day of month without leading zero
>dd - day of month with leadin zero
>
>thanx!
>
>hwee

This question belongs more to the general list, but anyway:

You can use strtotime() to convert various formats to a timestamp. Then use
date() to convert it back to your preferred date format:

$timestamp = strtotime($inputDate);
$isoDate = date('Y-m-d', $timestamp);

http://de2.php.net/strtotime
http://de2.php.net/manual/en/function.date.php

Regards, Torsten Roehr

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Check Boxes

am 18.08.2004 10:59:28 von balwantsingh

can somebody advise me
i want to use checkboxes on my website, i want that if user selects some
checkboxes (there will be more than 20 checkboxes), checkbox's value will be
stored in variables and than SELECT query command will be run using these
variables through PHP. but my problem is that in SELECT query command after
each column name comma (,) is required and if i use the same than it is
displaying "You have an error in your SQL syntax near 'FROM form' at line
1"

pls. help.



balwant

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Check Boxes

am 18.08.2004 11:31:01 von balwantsingh

i am using following coding


$a1 = $_POST['ch1'];
$a2 = $_POST['ch2'];
$a3 = $_POST['ch3'];

if ($a1 or $a2 or $a3) {
$query = "SELECT $a1, $a2, $a3 FROM form";
$result=@mysql_query ($query);
}
Enter_Date
Opening_Units
Unit_Consumed


-----Original Message-----
From: John Holmes [mailto:holmes072000@charter.net]
Sent: Wednesday, August 18, 2004 5:43 PM
To: balwantsingh@indoasian.com
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] Check Boxes




balwantsingh wrote:
> can somebody advise me
> i want to use checkboxes on my website, i want that if user selects some
> checkboxes (there will be more than 20 checkboxes), checkbox's value will
be
> stored in variables and than SELECT query command will be run using these
> variables through PHP. but my problem is that in SELECT query command
after
> each column name comma (,) is required and if i use the same than it is
> displaying "You have an error in your SQL syntax near 'FROM form' at line
> 1"

How about showing us some code.... kind of hard to help without that...


--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-GEN] Check Boxes

am 18.08.2004 11:32:56 von balwantsingh

balwantsingh wrote:
> can somebody advise me
> i want to use checkboxes on my website, i want that if user selects some
> checkboxes (there will be more than 20 checkboxes), checkbox's value will
be
> stored in variables and than SELECT query command will be run using these
> variables through PHP. but my problem is that in SELECT query command
after
> each column name comma (,) is required and if i use the same than it is
> displaying "You have an error in your SQL syntax near 'FROM form' at line
> 1"

i am using following coding

$a1 = $_POST['ch1'];
$a2 = $_POST['ch2'];
$a3 = $_POST['ch3'];

if ($a1 or $a2 or $a3) {
$query = "SELECT $a1, $a2, $a3 FROM form";
$result=@mysql_query ($query);
}
Enter_Date
Opening_Units
Unit_Consumed



balwant

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Check Boxes

am 18.08.2004 12:24:23 von Randy

If one of the checkboxes is NOT checked, then your query will break as
ift will look something like this:

SELECT xxx,,yyy FROM form;

Name your checkboxes like so: ch[]



Then you can loop through the checkbox array and run your query that way

$chkboxes =3D $_POST['ch'];
$sql =3D 'SELECT ';
foreach($chkboxes as $k =3D> $v)
{
=09$sql .=3D $v;
=09if($k < (sizeof($chkboxes) - 1))
=09{
$sql .=3D ', ';
=09}
}
$sql .=3D ' FROM form';


On Wed, 18 Aug 2004 15:01:01 +0530, balwantsingh
wrote:
> i am using following coding
>=20
> $a1 =3D $_POST['ch1'];
> $a2 =3D $_POST['ch2'];
> $a3 =3D $_POST['ch3'];
>=20
> if ($a1 or $a2 or $a3) {
> $query =3D "SELECT $a1, $a2, $a3 FROM form";
> $result=3D@mysql_query ($query);
> }
> Enter_Date
> Opening_Units ">
> Unit_Consumed ">
>=20
>=20
>=20
>=20
> -----Original Message-----
> From: John Holmes [mailto:holmes072000@charter.net]
> Sent: Wednesday, August 18, 2004 5:43 PM
> To: balwantsingh@indoasian.com
> Cc: php-db@lists.php.net
> Subject: Re: [PHP-DB] Check Boxes
>=20
> balwantsingh wrote:
> > can somebody advise me
> > i want to use checkboxes on my website, i want that if user selects som=
e
> > checkboxes (there will be more than 20 checkboxes), checkbox's value wi=
ll
> be
> > stored in variables and than SELECT query command will be run using the=
se
> > variables through PHP. but my problem is that in SELECT query command
> after
> > each column name comma (,) is required and if i use the same than it is
> > displaying "You have an error in your SQL syntax near 'FROM form' at l=
ine
> > 1"
>=20
> How about showing us some code.... kind of hard to help without that...
>=20
> --
>=20
> ---John Holmes...
>=20
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>=20
> php|architect: The Magazine for PHP Professionals â€=93 www.phparch.c=
om
>=20
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
>=20


--=20
randy sesser@gmail.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Check Boxes

am 18.08.2004 14:12:30 von John Holmes

balwantsingh wrote:
> can somebody advise me
> i want to use checkboxes on my website, i want that if user selects some
> checkboxes (there will be more than 20 checkboxes), checkbox's value will be
> stored in variables and than SELECT query command will be run using these
> variables through PHP. but my problem is that in SELECT query command after
> each column name comma (,) is required and if i use the same than it is
> displaying "You have an error in your SQL syntax near 'FROM form' at line
> 1"

How about showing us some code.... kind of hard to help without that...


--

---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: Date Conversion

am 18.08.2004 15:23:32 von Paul

You might want to look into date conversion on the MySQL side:

http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.ht ml

Look for

DATE_FORMAT(date,format)

Paul


On Wed, 18 Aug 2004 10:16:59 +0200, Torsten Roehr wrote:
> >"Ng Hwee Hwee" wrote in message
> news:009801c484f1$d11c8af0$800101df@hweehwee...
>
>
> >Hi all,
> >
> >can someone kindly point me to a resource that converts all kinds of
> possible date inputs into MySQL format of YYYY-MM-DD?
> >
> >example of formats to be converted includes:
> >
> >d/m/yy
> >d/m/yyyy
> >d/mm/yy
> >d/mm/yyy
> >dd/mm/yy
> >dd/mm/yyy
> >d/mmm/yy
> >d/mmm/yyyy
> >dd/mmm/yy
> >dd/mmm/yyyy
> >
> >yy - 2 digit representation of year
> >yyyy - ful numeric representation of year
> >m - numeric representation of month, without leading zero
> >mm - numeric representation of month, with leading zero
> >mmm - short textual representation of month
> >d - day of month without leading zero
> >dd - day of month with leadin zero
> >
> >thanx!
> >
> >hwee
>
> This question belongs more to the general list, but anyway:
>
> You can use strtotime() to convert various formats to a timestamp. Then use
> date() to convert it back to your preferred date format:
>
> $timestamp = strtotime($inputDate);
> $isoDate = date('Y-m-d', $timestamp);
>
> http://de2.php.net/strtotime
> http://de2.php.net/manual/en/function.date.php
>
> Regards, Torsten Roehr
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php