SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Date Conversion Problem

    Hey..guys!I need to transfer a string to date format.The script having error said that call to a member function parse() on a non-object.Thanks for your help...

    PHP Code:
    $reserve_date mysql_real_escape_string($_GET['selected_date']); 
        
    $reserve_time mysql_real_escape_string($_GET['showtime']); 
           
        
    $input_format date('dd.MM.yyyy HH:mm:ss'); //Europe standard
        
    $output_format date('yyyy-MM-dd HH:mm:ss'); //mySql standard
        
    $input_date $reserve_date " " $reserve_time;
        
    $date $input_format->parse($input_date); 

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    that's because $input_format isn't a class.
    Try this:
    PHP Code:
    $input_format 'dd.MM.yyyy HH:mm:ss'//Europe standard
    $output_format 'yyyy-MM-dd HH:mm:ss'//mySql standard
    $input_date $reserve_date " " $reserve_time;
    $date date($output_formatstrtotime($input_date)); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think is supposed to be alright,but I can't save the date to database?
    I define a column reserve_datetime as timestamp to store the date as the format defined in $output_format

    Code:
    $sql = <<<SQLSTM
            INSERT 
                INTO `reserve` 
                SET 
                    reserve_datetime = '$date' 
                   
    SQLSTM;

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Smile

    what happens if you put it in sprintf format, and change the insert query, like so:
    PHP Code:
    $sql sprintf("INSERT INTO `reserve` (`reserve_datetime`) VALUES ('%s')"$date
    ?
    Last edited by Jake Arkinstall; Oct 9, 2007 at 07:11. Reason: typo
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cannot. I still have some more columns need to insert value,how can I integrate them with sprintf format?

    Code:
    $sql = <<<SQLSTM
              INSERT 
                INTO `reserve` 
                SET 
                    reserve_datetime = '$date', 
                    seat_qty = $noOfSeat, 
                    ref_code = $refCode, 
                    movie_id = 1,
                    member_id = 1
    SQLSTM;

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    here you go:
    PHP Code:
    $sql sprintf("INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('%s', '%s', '%s', '1', '1')"$date$noOfSeat$refCode); 
    Last edited by Jake Arkinstall; Oct 9, 2007 at 07:29. Reason: code typo
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still can't store.Is it declaration problem?

    Code:
    `reserve_datetime` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
    The date actually is derived from here in previous page.

    Code:
    $date = date('D d\t\h M', strtotime('+' . $i . ' days'));

  8. #8
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can anyone help me to work out?Thanks a lot...

  9. #9
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    what does this output?:
    PHP Code:
    printf("INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('%s', '%s', '%s', '1', '1')"$date$noOfSeat$refCode); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  10. #10
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should be sprintf,because I can't insert any field with printf statement.
    For reserve_datetime only can't insert with sprintf.

  11. #11
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean the selected dates and times will be as follows:
    PHP Code:
    $reserve_date mysql_real_escape_string($_GET['selected_date']); 
    $reserve_time mysql_real_escape_string($_GET['showtime']);
    #example
    $reserve_date "10.10.2007"//dd.mm.yyyy
    $reserve_time "10:10:00"//hh:mm:ss 
    And you want it to convert as YYYY-MM-DD HH:MM:SS?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  12. #12
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My string format is not like that,it looks like

    $reserve_date = Fri 12th Oct;
    $reserve_time = 2:00pm;
    I need to combined them and parse to date format in pattern of "yyyy-MM-dd HH:mm:ss"

  13. #13
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So the time is always like 2:00pm, 3:00pm, 2:00am, etc only or there might be seconds too?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It should be sprintf,because I can't insert any field with printf statement.
    For reserve_datetime only can't insert with sprintf.
    No, you don't understand. Don't put it inside a query - just use it as a command. It will echo out the query - there might be a code break in the parsed version.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  15. #15
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    256
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, here the printout

    INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('70707070-JanJan-0101 0000:0101:0000', '2', '111945', '1', '1')

  16. #16
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    here you go:
    PHP Code:
    $output_format "y-m-d H:i:s"
    $reserve_date mysql_real_escape_string($_GET['selected_date']);
    $reserve_time mysql_real_escape_string($_GET['showtime']); 
    $date date($output_formatstrtotime($reserve_date.", ".$reserve_time));
    $sql sprintf("INSERT INTO `reserve` (`reserve_datetime`, `seat_qty`, `ref_code`, `movie_id`, `member_id`) VALUES ('%s', '%s', '%s', '1', '1')"$date$noOfSeat$refCode);
    mysql_query($sql); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

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