Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Edit: I figured it out, ill explain here.
I had the following code filled in
I didn't want the time part, just the year, day and month
//model
public DateTime Indate { get; set; } //this is filled in by a form with "01/01/2015"
//controller
(DateTime)person.Indate).ToString("dd-MM-yyyy")
What i Failed to notice is that this only applied for that line code, i missed out on adding that line EVERYWHERE.
htmlBody1 += "<tr><td style=\"width: 225px\">Starting Date Project </td><td>: " + person.Indate + "</td></tr>";
This was my incorrect line, i forgot to add the .ToString("dd-MM-yyyy") there aswell
I solved it.
thanks to Damien_The_Unbeliever, for pointing out that it does not remember your format if you output it sometimes. this made me realise i had to specficly point out out everywhere.
I just ran this code and it outputs exactly what you you want:
You can also use ToString("d"), which will output 28.10.2014 (based on your culture), or ToShortDateString(), which will output the same.
You're missing a parenthesis in the code shown. Your formatting statement isn't valid C# code.
With that saud, this works for me:
DateTime date = DateTime.Now;
System.Console.WriteLine(((DateTime)date).ToString("dd-MM-yyyy"));
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I tried making a program where every few seconds a random letter dropped. I noticed that the "correct" one dropped to rarely. I made a int correctLetterDrop = Random.Range(0,100) and wanted to artificially increase the chance. The rest of the code handles everything, i just need to assign the correct sprite to check against.
This gives me an error at the .correctSprite; saying "else cannot start a statement". I expect it to just check if the Random.Range returned 7 or less (for a 7% chance) and if it did to set the correct one, and otherwise just set a random one.
if(correctLetterDrop <= 7){
Clone.GetComponent<SpriteRenderer>().sprite = correctLetterScript.correctSprite;
else{
Clone.GetComponent<SpriteRenderer>().sprite = Letters[Letter];
}
}
Check for the first if condition closure }:
if(correctLetterDrop <= 7) {
Clone.GetComponent<SpriteRenderer>().sprite = correctLetterScript.correctSprite;
}else{
Clone.GetComponent<SpriteRenderer>().sprite = Letters[Letter];
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
string entryStr = "3";
Console.WriteLine(entryStr);
Regex regex = new Regex("[abcdef]");
Regex numRegex = new Regex("[0123456789]");
Console.WriteLine("entryStr: " + entryStr);
Console.WriteLine("[a-f]: " + regex.IsMatch("entryStr"));
Console.WriteLine("[0-9]: " + numRegex.IsMatch("entryStr"));
/* result:
entryStr: 3
[a-f]: True
[0-9]: False
*/
I'm trying to work with Regex, and it gives me seemingly wrong results.
I need to check if a certain string fits one Regex pattern or another.
I wrote this code, and the code seems correct to me, but it seems to give a wrong result and seems to consider the string "3" as fitting the "[a-f]" pattern and not the "[0-9]".
What did I misunderstand?
Thanks for the replies and sorry for the fundamental question.
You are passing the string literal "entryStr" to isMatch(), when you really want to pass the variable itself by the same name. That is, use this version to get your expected results:
Console.WriteLine("entryStr: " + entryStr);
Console.WriteLine("[a-f]: " + regex.IsMatch(entryStr));
Console.WriteLine("[0-9]: " + numRegex.IsMatch(entryStr));
This prints:
entryStr: 3
[a-f]: False
[0-9]: True
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to add a link and image to a gridview when certain conditions are met.
I think that it can be done using the below code, but I get confused about where the " go and I know that some of them need to be \" but I'm not sure where. At the moment this won't compile, please could someone help me with this?
I've also investigated using an image button but that way seems more complex in my case, as the button should only appear in rows that fit the conditions. I'm open to using that method instead if you think that it's better.
if(line.SuperSessionIndicator == "1" || line.ErrorType =="S" )
{
lbl3.Text = "<aref=\"https://stackoverflow.com/questions/7167839/aspimage-with-link \">"<img url='Images/Prop.png\'/>\"\"<a/>";
}
You need to use following code to get it right.
lbl3.Text = "<a href=\"https://stackoverflow.com/questions/7167839/aspimage-with-link\"><img src='Images/Prop.png\'/><a/>";
The resulting markup from above C# code would be as below which looks correct.
<a href="https://stackoverflow.com/questions/7167839/aspimage-with-link"><img src='Images/Prop.png'/><a/>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Can somebody kindly help in addressing this issue:
string datetime = DateTime.Today.ToString("yyyymmdd")
I would like to have date in the yyyymmdd format without any separator in between.
Please stop downvoting this question. I got the message loud and clear that this question lacks research effort and also doesn't add an iota of usefulness to the SO programming.
try
string todayDate = DateTime.Today.ToString("yyyyMMdd");
Except from:
string todayDate = DateTime.Today.ToString("yyyyMMdd");
You could also use:
string todayDate = DateTime.Now.ToString("yyyyMMdd");
In your case it is actually doing the same thing. If you want so get it more specific I think .Now is better.
For all of the different possibilities take a look at this link:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
try this:
string todayDate = DateTime.Today.ToString("yyyyMMdd")
The correct DateTime format string would be yyyyMMdd.
The month part of your string should be MM (month from 01 to 12) instead of mm:
string todayDate = DateTime.Now.ToString("yyyyMMdd");
Source:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I can find a lot of info about parsing but I would like to put them together. I am trying to get the City, State, and Zip and place them in a single Label on a winform like 'City, State Zip' here is what I have gotten to but they will not get together.
while (sqlDataReader.Read())
{
label_vendor_Address.Text = sqlDataReader["Vendor_Address"].ToString();
string vendor_City = sqlDataReader["Vendor_City"].ToString();
string vendor_State_Prov = sqlDataReader["Vendor_State_Prov"].ToString();
string vendor_Zip_Country_Code = sqlDataReader["Vendor_Zip_Country_Code"].ToString();
label_vendor_City_State_Zip.Text = vendor_City, vendor_State_Prov, vendor_Zip_Country_Code;
}
I am sure that I am missing something very simple. Help is gratefully appreciated.
Is it as simple as this:
label_vendor_City_State_Zip.Text = vendor_City + ", " + vendor_State_Prov + " " + vendor_Zip_Country_Code;
Surely, not though, as your code would not compile. Can you provide code that can compile?