Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    varchar date convert to date

    hi i have a date as

    Varchar type date 10/08/2013 so i need to convert this date to mysql date type as 2013-08-10


    how do i do this plz help me to do this

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Posts
    428
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Code:
    $newDate = date("Y-m-d", strtotime($oldDate);

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    There's not enough information here to determine whether strtotime or datetime can be used directly. The format of 10/08/2013 is either August 10, 2013 or October 8, 2013 which was not specified by the OP.
    If it stands for October 8, 2013, you can use strtotime or DateTime directly. If it stands for August, you must separate the date parts using explode or any similar method, and manually construct it using mktime or datetime::setdate functions.

    Since the SQL date of 2013-08-10 is August 10, 2013, you'll need to do it manually by splitting the components up and using the mktime or datetime::setdate functions. If the data is already in SQL you can use the SQL functions to copy it over directly. You can look at the str_to_date function for that. I assume you're trying to copy this over to a new property in a table; without proper DateTime datatypes in SQL you cannot properly search or sort by dates provided.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •