PHP

Moderators: None (Apply to moderate this forum)
Number of threads: 1848
Number of posts: 5016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by sharingan on 14 Feb 2007 at 8:27 PM
This message was edited by sharingan at 2007-2-14 20:39:29

hello...

somebody please help me using php codes for below problems..

I have one form that require 2 input box

1st input box = date_start
2nd input box = date_end

user will input the date format dd/mm/yyy on the input box 1 and 2.
the problem is how do I convert from (dd/mm/yyyy) to (yyyy/mm/dd) format when the user save the form?


Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by Agbagbara on 15 Feb 2007 at 11:57 PM
: This message was edited by sharingan at 2007-2-14 20:39:29

: hello...
:
: somebody please help me using php codes for below problems..
:
: I have one form that require 2 input box
:
: 1st input box = date_start
: 2nd input box = date_end
:
: user will input the date format dd/mm/yyy on the input box 1 and 2.
: the problem is how do I convert from (dd/mm/yyyy) to (yyyy/mm/dd) format when the user save the form?
:
:
Hi

What you could do is to use strtotime($dString) which created a timestamp then format the timestamp using date('Y/m/d')or what ever format u wish.
This is the function which I use to format date
function formatDate($dDate){
$dNewDate = strtotime($dDate);
return date('Y/m/d H:i:s',$dNewDate);
}

Omo


Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by sharingan on 16 Feb 2007 at 12:12 AM
: : This message was edited by sharingan at 2007-2-14 20:39:29

: : hello...
: :
: : somebody please help me using php codes for below problems..
: :
: : I have one form that require 2 input box
: :
: : 1st input box = date_start
: : 2nd input box = date_end
: :
: : user will input the date format dd/mm/yyy on the input box 1 and 2.
: : the problem is how do I convert from (dd/mm/yyyy) to (yyyy/mm/dd) format when the user save the form?
: :
: :
: Hi
:
: What you could do is to use strtotime($dString) which created a timestamp then format the timestamp using date('Y/m/d')or what ever format u wish.
: This is the function which I use to format date
: function formatDate($dDate){
: $dNewDate = strtotime($dDate);
: return date('Y/m/d H:i:s',$dNewDate);
: }
:
: Omo
:
:
: here is my sql code

$result = mysql_query( "UPDATE employee_list SET e_name='{$_POST['e_name']}', passport='{$_POST['passport']}', permit_owner='{$_POST['permit_owner']}', date_arrived='{$_POST['date_arrived']}', date_expired='{$_POST['date_expired']}', nationality='{$_POST['nationality']}', workplace='{$_POST['workplace']}', status='{$_POST['status']}', notes='{$_POST['notes']}' WHERE passport ='{$_POST['passport']}'");


note that the 'date_arrived' and 'date_expired' is in dd/mm/yyyy format but i want when the data is update it will be save in yyyy/mm/dd format.

is it posible to change the sql codes only?

Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by Agbagbara on 16 Feb 2007 at 3:07 AM
: : : This message was edited by sharingan at 2007-2-14 20:39:29

: : : hello...
: : :
: : : somebody please help me using php codes for below problems..
: : :
: : : I have one form that require 2 input box
: : :
: : : 1st input box = date_start
: : : 2nd input box = date_end
: : :
: : : user will input the date format dd/mm/yyy on the input box 1 and 2.
: : : the problem is how do I convert from (dd/mm/yyyy) to (yyyy/mm/dd) format when the user save the form?
: : :
: : :
: : Hi
: :
: : What you could do is to use strtotime($dString) which created a timestamp then format the timestamp using date('Y/m/d')or what ever format u wish.
: : This is the function which I use to format date
: : function formatDate($dDate){
: : $dNewDate = strtotime($dDate);
: : return date('Y/m/d H:i:s',$dNewDate);
: : }
: :
: : Omo
: :
: :
: : here is my sql code
:
: $result = mysql_query( "UPDATE employee_list SET e_name='{$_POST['e_name']}', passport='{$_POST['passport']}', permit_owner='{$_POST['permit_owner']}', date_arrived='{$_POST['date_arrived']}', date_expired='{$_POST['date_expired']}', nationality='{$_POST['nationality']}', workplace='{$_POST['workplace']}', status='{$_POST['status']}', notes='{$_POST['notes']}' WHERE passport ='{$_POST['passport']}'");
:
:
: note that the 'date_arrived' and 'date_expired' is in dd/mm/yyyy format but i want when the data is update it will be save in yyyy/mm/dd format.
:
: is it posible to change the sql codes only?
:
:
Hi.

What you have to do is to split the date_arrive and date_expire based on the seperator ie "/"
$arrive = explode($_POST['date_arrive'],"/");
$arrive[0] =dd
$arrive[1] =mm
$arrive[2] =yyyy

then swap them round
$new_arrive = sprintf("%s/%s/%s",$arrive[2],$arrive[1],$arrive[0]);

All this is based on the assumption that the user entered the dates in the right format.

so since you are going to do this more than once, you would have to write a function.

Omo

Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by sharingan on 16 Feb 2007 at 4:25 AM
: : : : This message was edited by sharingan at 2007-2-14 20:39:29

: : : : hello...
: : : :
: : : : somebody please help me using php codes for below problems..
: : : :
: : : : I have one form that require 2 input box
: : : :
: : : : 1st input box = date_start
: : : : 2nd input box = date_end
: : : :
: : : : user will input the date format dd/mm/yyy on the input box 1 and 2.
: : : : the problem is how do I convert from (dd/mm/yyyy) to (yyyy/mm/dd) format when the user save the form?
: : : :
: : : :
: : : Hi
: : :
: : : What you could do is to use strtotime($dString) which created a timestamp then format the timestamp using date('Y/m/d')or what ever format u wish.
: : : This is the function which I use to format date
: : : function formatDate($dDate){
: : : $dNewDate = strtotime($dDate);
: : : return date('Y/m/d H:i:s',$dNewDate);
: : : }
: : :
: : : Omo
: : :
: : :
: : : here is my sql code
: :
: : $result = mysql_query( "UPDATE employee_list SET e_name='{$_POST['e_name']}', passport='{$_POST['passport']}', permit_owner='{$_POST['permit_owner']}', date_arrived='{$_POST['date_arrived']}', date_expired='{$_POST['date_expired']}', nationality='{$_POST['nationality']}', workplace='{$_POST['workplace']}', status='{$_POST['status']}', notes='{$_POST['notes']}' WHERE passport ='{$_POST['passport']}'");
: :
: :
: : note that the 'date_arrived' and 'date_expired' is in dd/mm/yyyy format but i want when the data is update it will be save in yyyy/mm/dd format.
: :
: : is it posible to change the sql codes only?
: :
: :
: Hi.
:
: What you have to do is to split the date_arrive and date_expire based on the seperator ie "/"
: $arrive = explode($_POST['date_arrive'],"/");
: $arrive[0] =dd
: $arrive[1] =mm
: $arrive[2] =yyyy
:
: then swap them round
: $new_arrive = sprintf("%s/%s/%s",$arrive[2],$arrive[1],$arrive[0]);
:
: All this is based on the assumption that the user entered the dates in the right format.
:
: so since you are going to do this more than once, you would have to write a function.
:
: Omo
:
:
oooo...
thanks alot man...
i think ive got it....
:p

Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by tradm on 19 Feb 2007 at 12:08 AM
You got it dude!
Next tym consider [dd\/][mm\/][yyyy\/] - Drop down
O the best.
Report
Re: corvert date to (dd-mm-yyyy to yyyy-mm-dd) format Posted by lostair on 5 Jul 2007 at 4:44 AM
This doesn't seem to work in PHP. All i get is the following:

13/05/1985
1970/01/01 01:00:00 <-- this should be 1985/05/13 01:00:00

David



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.