Results 1 to 8 of 8

Thread: SQL Insert with UNIX_TIMESTAMP

  1. #1

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067

    SQL Insert with UNIX_TIMESTAMP

    Ok, I hope someone can help. Here's my dilemma.
    I want to use a INSERT INTO statement into a MySQL table that needs the following information.

    A Start date (Unix timestamp)
    A Start time (Unix timestamp)
    A End time (Unix timestamp)

    I have no idea how to convert this into a series of INSERT statements.

    I already tried INSERT INTO <table> VALUES (UNIX_TIMESTAMP('04/04/2003')
    This works but as no time in included in the date string, I get the wrong value.

    The whole purpose of this is to take 3 strings (above) from a VB form and write a INSERT statement that I can then load in PHP which will fill the table entries properly.

    Please help. I would like an example based on Date : 04/04/2003, starttime 12:00, Endtime 17:00

    Regards,
    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  2. #2
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Isn't there a DATESTAMP? If not, the now() function in MySQL inserts a date and a time
    Place Your VBForums Ad Here

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm assuming you're doing this through PHP?

    Code:
    $sql = "INSERT INTO table VALUES ('" . strtotime("04/03/03") . "')";
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Originally posted by The Hobo
    [B]I'm assuming you're doing this through PHP?
    No I'm not. What I am doing is generating a text file which consists of INSERT statements. I am then uploading tht text file to MySQL tables using PHPmYAdmin. I can not use standard PHP commands for this, only transact SQL.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Mega_Man
    No I'm not. What I am doing is generating a text file which consists of INSERT statements. I am then uploading tht text file to MySQL tables using PHPmYAdmin. I can not use standard PHP commands for this, only transact SQL.

    Mega.
    Ah, forgive me for assuming that this was a PHP question. Not like it's a PHP forum or anything.

    I just looked it up, and UNIX_TIMESTAMP(date) should work fine...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    I was uncertain as to which forum I should post this in but never mind

    Anyway,
    Yes the UNIX_TIMESTAMP works fine for a date. The problem I have is how to convert a time into a unix timestamp and store that in a field.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Just do it the same way:

    Code:
    UNIX_TIMESTAMP('04/04/03 15:26:00')
    My evil laugh has a squeak in it.

    kristopherwilson.com

  8. #8

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Ah, the proverbial penny has dropped I think.
    I will try this method.

    Thanks,
    Mega.
    "If at first you don't succeed, then skydiving is not for you"

Posting Permissions

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



Click Here to Expand Forum to Full Width