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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2009
    Location
    Dallas,Tx USA
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts

    strip off '/' from date while comparing with database

    Helo there,

    In my databse date is stored like 10292009. without slash....
    in the UI I have a javascript popup calendar which allows to select date in 10/29/2009.
    Now I have a purge page where i had a condition

    PHP Code:

        $purgeSQL 
    sprintf("DELETE FROM timesheet.timeclock WHERE sdateentry <= $DateValue "GetSQLValueString($_POST['OldestDate'], "text"));
    I am trying to strip the slashe or or any others  by using this array...

    $arrFrom = array('"',"'","/",".","_","(",")","+");
        
    $dateentered="%s";
        
    $DateValue str_replace($arrFrom""$dateentered); 
    But still it is sending the value with / slash for comparison.
    Plzz Help........
    Last edited by gadaschowdary; 10-30-2009 at 06:37 PM. Reason: spelt wrong so.....

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    what sort of database is it ~ MySQL? If so, you should be storing your dates in the db where the column is formatted for date. 2009-10-20 for example - the ISO format.

    You could use a timestamp but DATE has been created exactly for what you are trying to do.

    Anyhoo, to strip slashes, there is a feature in php called something like, 'stripslashes' or, you could use a regex. I don't use php much so I shan't give you code to work with because, it could waste your time if it were wrong.

    but it is something like

    $var =~ s/\///g;

    empty regex like this s///; and it means substitute whats between the first two slashes with what is between the second two. so I have put an escaped slash in the first place and nothing in the second place because we want to substitute it with nothing. 'g' means apply it globally to the string so all slashes are to be stripped out. leave out the 'g' and it only strips the first slash.

    hth

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #3
    New Coder
    Join Date
    Oct 2009
    Location
    Dallas,Tx USA
    Posts
    54
    Thanks
    4
    Thanked 0 Times in 0 Posts
    it is postgresql

    thank you..

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    In my databse date is stored like 10292009. without slash....
    That's really a bad design. You need to use a datetime/date format, to get the full advantage of DB
    Last edited by abduraooft; 10-31-2009 at 04:10 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    you can't compare two dates using arithmetic operators like <.>,<= and =>, have no sence since a date have three components.
    you can use to_date(yourdate,"MMDDYYYY") to format a date as you ask in progresql but as I said this don't help you.

    best regards


  •  

    Posting Permissions

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