corvert date to (dd-mm-yyyy to yyyy-mm-dd) format - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

corvert date to (dd-mm-yyyy to yyyy-mm-dd) format

sharingansharingan Posts: 15Member
[b][red]This message was edited by sharingan at 2007-2-14 20:39:29[/red][/b][hr]
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?


Comments

  • AgbagbaraAgbagbara Posts: 24Member
    : [b][red]This message was edited by sharingan at 2007-2-14 20:39:29[/red][/b][hr]
    : 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


  • sharingansharingan Posts: 15Member
    : : [b][red]This message was edited by sharingan at 2007-2-14 20:39:29[/red][/b][hr]
    : : 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?

  • AgbagbaraAgbagbara Posts: 24Member
    : : : [b][red]This message was edited by sharingan at 2007-2-14 20:39:29[/red][/b][hr]
    : : : 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

  • sharingansharingan Posts: 15Member
    : : : : [b][red]This message was edited by sharingan at 2007-2-14 20:39:29[/red][/b][hr]
    : : : : 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

  • tradmtradm Posts: 49Member
    You got it dude!
    Next tym consider [dd/][mm/][yyyy/] - Drop down
    O the best.
  • lostairlostair Posts: 1Member
    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
Sign In or Register to comment.