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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    formatting a date string?

    How can i format a string like this: 20060102095848

    into something like:

    January 2nd, 2006

    I don't need the time part of that, but what im not sure is how to split it up reliably for all different strings of the same type.

  • #2
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    *added information*

    Im using now()

    Is there another code that will format it the way i want?

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, im getting mysql errors saying my syntax is wrong on this. Im not sure why it is though.

    PHP Code:
    $query1 "INSERT INTO tutorials (date,image,title,description,link,category,author) VALUES (date('F jS, Y'),'".$image."','".$title."','".$description."','".$link."','".$category."','".$author."')";
    mysql_query($query1)or die(mysql_error());
    ?> 

  • #5
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by thesavior
    ok, im getting mysql errors saying my syntax is wrong on this. Im not sure why it is though.

    PHP Code:
    $query1 "INSERT INTO tutorials (date,image,title,description,link,category,author) VALUES (date('F jS, Y'),'".$image."','".$title."','".$description."','".$link."','".$category."','".$author."')";
    mysql_query($query1)or die(mysql_error());
    ?> 
    date('F jS, Y') is in quotation marks, but it's not a MySQL function, it's a PHP function.

  • #6
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ok, so then how can i do this with mysql then?

  • #7
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    errr, don't.

    PHP Code:
    $query1 "INSERT INTO tutorials (date,image,title,description,link,category,author) VALUES ('".date('F jS, Y')."','".$image."','".$title."','".$description."','".$link."','".$category."','".$author."')"

  • #8
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    See DATE_FORMAT() on MySQL data and time functions.

    Edit: Ralph's works just fine, but when selecting data DATE_FORMAT() would be useful. You could use this anyways, but the PHP solution works just as well.
    "$question = ( to() ) ? be() : ~be();"

  • #9
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    his didn't work, im getting an error:


    PHP Code:
    $query1 "INSERT INTO tutorials (date,image,title,description,link,category,author) VALUES ('".date('F jS, Y')."','".$image."','".$title."','".$description."','".$link."','".$category."','".$author."')"

    Parse error: parse error, unexpected T_VARIABLE in c:\phpdev5\www\tms\processtut.php on line 13

  • #10
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    Quote Originally Posted by thesavior
    his didn't work, im getting an error:


    PHP Code:
    $query1 "INSERT INTO tutorials (date,image,title,description,link,category,author) VALUES ('".date('F jS, Y')."','".$image."','".$title."','".$description."','".$link."','".$category."','".$author."')"

    Parse error: parse error, unexpected T_VARIABLE in c:\phpdev5\www\tms\processtut.php on line 13
    Are you missing a semicolon on the line preceeding this?

  • #11
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    ...no... :rolleyes and look innocent:

    lol

  • #12
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    what does this error mean, and how do i fix it?

    You have an error in your SQL syntax near 'desc) VALUES ('January 2nd, 2006','aj;lkajfl;kjads;fkj','flk;lajd;lfkj;lasdjf','' at line 1
    PHP Code:
    <?php
    // set your information.
    $dbhost='localhost';
    $dbusername='root';
    $dbuserpass='';
    $dbname='test';

    // connect to the mysql database server.
    mysql_connect ($dbhost$dbusername$dbuserpass);

    if (!
    mysql_select_db($dbname)) die(mysql_error());
    $now date('F jS, Y');
    $query1 "INSERT INTO tutorials (date,image,title,tuturl,category,author,desc) VALUES ('".date('F jS, Y')."','".$image."','".$title."','".$url."','".$category."','".$author."','".$desc."')"
    mysql_query($query1)or die(mysql_error());
    ?>

  • #13
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    I don't have mysql right now to check but my guess is it's because DESC is an SQL keyword meaning DESCending in the ORDER BY clause. Change the column name or try putting it in quotes or something and see if you can't get it working.

  • #14
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    what is the MySQL type of the 'date' field ? (and is that also a reserved word in MySQL in which case use `date` (with the backticks) in fact use backticks on all the fieldnames anyway `desc` etc)

    In your initial post you showed a MySQL timestamp(14) , if thats the type of the date field then thats the sort of input its expecting.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #15
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    oh sorry, i forgot to post a "IT WORKS!! W00t!!! post"

    It works now, i just changed desc to descr

    Thanks guys for all your help and quick replies.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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