Wednesday, March 28, 2012
text date conversion
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
DanDateTime.ToString("yyyy-MM-dd");
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
Hi peeps
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
Dan
Easy,
Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:
[mm]
[dd]
[yyyy]
Then swap array positions so you get:
[yyyy]
[mm]
[dd]
Then join the array using the "-" character.
Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.
"dhnriverside" wrote:
> Hi peeps
> I have a datepicker control that's providing dates in the format dd/mm/yyy
y
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid() an
d
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
Hi Charles
Thanks for that. Yeah it was very newbie. The original system was written
with Access/ASP and as I said I had tremendous trouble with pulling dates ou
t
the database.
Sussed that now, but im writing V2, it's just easier to continue with this
system than converting allllll the data :o)
Cheers for the answer!
Dan
"Charles Chen" wrote:
> Easy,
> Split the string "mm/dd/yyyy" into an array using the delimiter "/" so tha
t
> you get:
> [mm]
> [dd]
> [yyyy]
> Then swap array positions so you get:
> [yyyy]
> [mm]
> [dd]
> Then join the array using the "-" character.
> Why you would choose to store DATES as STRINGS is beyond me (just sounds
> like a really, really newbie solution)...but if it floats your boat, then
> there's your solution.
> "dhnriverside" wrote:
>
Dan,
You could always use the build in formatting on the DateTime object.
string s = "25/12/2004"
DateTime d = DateTime.ParseExact( s, "d/M/yyyy", null );
Now the variable 'd' will hold the date exactly as Dec 25, 2004.
You can get the date back out in any format you want using the .ToString()
method.
Console.WriteLine( d.ToString( "yyyy-MM-dd" ) )
Here are a couple links for DateTime formatting. These are gem pages for
working with any DateTime formatting issues.
http://msdn.microsoft.com/library/d...rmatstrings.asp
http://msdn.microsoft.com/library/d...rmatstrings.asp
Happy formatting!
bill
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
> Hi peeps
> I have a datepicker control that's providing dates in the format
dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid()
and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
text date conversion
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
DanDateTime.ToString("yyyy-MM-dd");
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
Hi peeps
I have a datepicker control that's providing dates in the format dd/mm/yyyy
(UK).
I want to convert this to "yyyy-mm-dd" to store as a text field in my
database (had lots of problems with date conversions using "proper" data
fields).
I used to use ASP, and it was easy, using a combination of Left() Mid() and
Right(), but I can't work out how to do this conversion in C#.
Help appreciated!
Cheers
Dan
Easy,
Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
you get:
[mm]
[dd]
[yyyy]
Then swap array positions so you get:
[yyyy]
[mm]
[dd]
Then join the array using the "-" character.
Why you would choose to store DATES as STRINGS is beyond me (just sounds
like a really, really newbie solution)...but if it floats your boat, then
there's your solution.
"dhnriverside" wrote:
> Hi peeps
> I have a datepicker control that's providing dates in the format dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid() and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
Hi Charles
Thanks for that. Yeah it was very newbie. The original system was written
with Access/ASP and as I said I had tremendous trouble with pulling dates out
the database.
Sussed that now, but im writing V2, it's just easier to continue with this
system than converting allllll the data :o)
Cheers for the answer!
Dan
"Charles Chen" wrote:
> Easy,
> Split the string "mm/dd/yyyy" into an array using the delimiter "/" so that
> you get:
> [mm]
> [dd]
> [yyyy]
> Then swap array positions so you get:
> [yyyy]
> [mm]
> [dd]
> Then join the array using the "-" character.
> Why you would choose to store DATES as STRINGS is beyond me (just sounds
> like a really, really newbie solution)...but if it floats your boat, then
> there's your solution.
> "dhnriverside" wrote:
> > Hi peeps
> > I have a datepicker control that's providing dates in the format dd/mm/yyyy
> > (UK).
> > I want to convert this to "yyyy-mm-dd" to store as a text field in my
> > database (had lots of problems with date conversions using "proper" data
> > fields).
> > I used to use ASP, and it was easy, using a combination of Left() Mid() and
> > Right(), but I can't work out how to do this conversion in C#.
> > Help appreciated!
> > Cheers
> > Dan
Dan,
You could always use the build in formatting on the DateTime object.
string s = "25/12/2004"
DateTime d = DateTime.ParseExact( s, "d/M/yyyy", null );
Now the variable 'd' will hold the date exactly as Dec 25, 2004.
You can get the date back out in any format you want using the .ToString()
method.
Console.WriteLine( d.ToString( "yyyy-MM-dd" ) )
Here are a couple links for DateTime formatting. These are gem pages for
working with any DateTime formatting issues.
http://msdn.microsoft.com/library/d...rmatstrings.asp
http://msdn.microsoft.com/library/d...rmatstrings.asp
Happy formatting!
bill
"dhnriverside" <dan@.musoswire.com> wrote in message
news:F96893C8-D39B-4207-B3C9-861A42594CD5@.microsoft.com...
> Hi peeps
> I have a datepicker control that's providing dates in the format
dd/mm/yyyy
> (UK).
> I want to convert this to "yyyy-mm-dd" to store as a text field in my
> database (had lots of problems with date conversions using "proper" data
> fields).
> I used to use ASP, and it was easy, using a combination of Left() Mid()
and
> Right(), but I can't work out how to do this conversion in C#.
> Help appreciated!
> Cheers
>
> Dan
text document into html template
can any one help me to convert a normal text document into a html template. I have around 50docs need to convert them into html templates and use those templates to generate html reports.
Thanks in advance,,chandras17--
Regarding this...
chandras17 wrote:
...can any one help me to convert a normal text document into a html template...
...it is not quite clear to me what you mean by "html template", but...
...one quick and simple way to display a text document in a browser is to surround the text by pre tags and give the document an "htm" extension...
...for example, suppose the file "Test.txt" contains the following...
This some sample text.
It is in a file.
The file is a plain text file.
...then, to view that file in a browser, one can simply copy the file, rename the copy to "Test.txt.htm", and change the contents to the following...
<pre>
This some sample text.
It is in a file.
The file is a plain text file.
</pre>
...and then load "Test.txt.htm" into a browser.
That is a simple way.
The case shown is simple; you do need to handle special characters. You can see some sample code in my "dirt-simple" code-viewer, (but you will have to download the code and pull it apart because it doesn't exactly fit your requirement), found at...
http://www.WebLogicArts.com/DemoList.aspx
HTH.
Saturday, March 24, 2012
text to html
Can someone help me out please?I think I didn't explain myself well enough..
I have a textbox and when people type something out like this:
***************
This is my first line
This is my second line
***************
once I pull it out of a database, I want it to be displayed the same way... So it is displayed the way I type it out, like any of the posts on this board.
Can someone please help?
Assume that your text is stored in myString
If u want to convert it to html, use server.htmlencode(myString), it will convert sth. like "<" to "<". But it can't automatically generate <br>. So you have to use replace to do that
Finally, you can use
replace(server.htmlencode(myString), vbcrlf,"<br>")
BTW, basically, I will keep the original text in database, only encode them when output.
Why I do like that? Because when you want to update it, the html code will also be shown on the textbox for update, it confused the user much. So you'd better do the encoding in output, not do it when inserting it into database.
string temp = TextBox1.Text.ToString() + "<BR>";
Response.Write(temp);
that will do the trick
Thanks, got it working now...
Though there's a different way to encode it as html and stuff...
Thanks for the suggestion rgao906. It's a good idea
Lomex if you out three how do you do it?
when I used textbox.text i get a whole string like this:
Line 1. Line2.
I tried the above it doesn't insert the necessary <br
please help!