Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Date to text format 1

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi All,

I've been working on this for days and I can't find a solution. It's the last little detail that I have to complete before I can send this to the customer.

I have written a blog systme using ASP and have an Archive menu that displays an archive of posts by month and year.(ie Jun-2008)

I get this by doing the following:
1. When the user posts some content into the blog, a hidden field records <%Date()%> as a value. The field is set as a short date in the database.

2. There is another field that records the date but this time it records the 1st day of the month as such:
Code:
<%
Dim Mymonth
Mymonth = Date()
Response.write "1-"&MonthName(Month(Mymonth),true)&"-"& Right(Year(Mymonth),2)
%>
This field is used by the SQL to select the distinct records and allows me to sort the records in descending order.
The third field is used to display the actual month and year and is written from the date code into a string format as such
Code:
<% 
Dim ArcDate
ArcDate = MonthName(Month(Mymonth),true)&"-"& Right(Year(Mymonth),4)
cstr(ArcDate)
Trim(ArcDate)
Response.Write(ArcDate)
%>
all of the data enters the fields in the database with out any errors.

The problem lies with the data in the last field. for some reason it sends the text"Jun-2008" into the field with 11 spaces before and 13 spaces after the text. and looks like:
Code:
"           June-2008      
       "

I have tried to remove the spaces with the TRIM function as you can see above, but to no avail.

How can I achieve this effectively?

I have used three fields for a number of reasons
1. I can't use the date the post was written as a Distinct query as all the dates would appear.
2. I can't use the Archive date fiedl in date format because I use sessions to call the page that displays the relevant records for that particular month and it will not allow a search of "Jun-2008" as a date.

I have found that I need two fields, one with the first of the month for each post written in that month and one as a text field to sort the data by. It will work fine, except for all of those white spaces in the text field.

Any suggestion would be appreciated.

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
you can take the string
" JUN-2008 "
and parse it one character at a time and put the non-blank or non-null chars in the new field. \
Code:
bad_string = "           JUN-2008             "
new_string = "" 
for i = 1 to len(bad_string) 
    x = mid(bad_string, i, 1)  
    if x > " "  then 
       new_string = new_string & x
    end if 
next





 
I Think You Have it! nice work. Here is what I had to place into the input field before i inserted the table
Code:
<input type="hidden" name="ArcMth" id="ArcMth" value="<%
		  Dim bad_string, new_string
		  bad_string =(blog_list.Fields.Item("ArchMonth").Value)
		  	new_string = ""
			for i = 1 to len(bad_string)
    		x = mid(bad_string, i, 1)  
    		if x > " "  then
       		new_string = new_string & x
    		end if
			next
		  Response.Write(new_string)		  
		  %>" />

I can't hep but think however that we have only treated the symptoms and not fixed the problem. What would have caused this in the first place?

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Code:
<%
dim s,rx
s="     J A N - 2 0 0 8       "

set rx=new regexp
with rx
    .global=true
    .pattern="\s"
end with
s=rx.replace(s,"")
%>

<input type="hidden" name="ArcMth" id="ArcMth" value="<%=s%>" />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top