View Full Version : strip off '/' from date while comparing with database

10-30-2009, 06:37 PM
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

$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('"',"'","/",".","_","(",")","+");
$DateValue = str_replace($arrFrom, "", $dateentered);

But still it is sending the value with / slash for comparison.
Plzz Help........

10-30-2009, 06:56 PM
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.



10-31-2009, 03:36 PM
it is postgresql

thank you..

10-31-2009, 03:58 PM
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

10-31-2009, 03:58 PM
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