WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2024 Poal.co

1.4K

C#

Trying to get a date out of a string. For some reason this is not working. Could be I'm tired and just don't see it. The date it should get is 2017-10-05 but it does not detect a date at all.

file = "171005_010"

f = Regex.Replace(file, "[^0-9]", "");
if (f.Length >= 6)
{
    try
    {
        bool z = DateTime.TryParseExact(f.Substring(0, 6), "yyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result);
        string y = result.ToString();
        if (z)
        {
            return result.ToString(dateformat);
        }
    }
    catch (Exception ee)
    {
        return null;
    }
}





EDIT

Found the problem.

changed

f = Regex.Replace(file, "[^0-9]", "");

to

f = Regex.Replace(f, "[^0-9]", "");

file did NOT = "171005_010"

Almost never fails. Just have to ask before I figure it out.

C# Trying to get a date out of a string. For some reason this is not working. Could be I'm tired and just don't see it. The date it should get is 2017-10-05 but it does not detect a date at all. ``` file = "171005_010" f = Regex.Replace(file, "[^0-9]", ""); if (f.Length >= 6) { try { bool z = DateTime.TryParseExact(f.Substring(0, 6), "yyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result); string y = result.ToString(); if (z) { return result.ToString(dateformat); } } catch (Exception ee) { return null; } } ``` EDIT Found the problem. changed `f = Regex.Replace(file, "[^0-9]", "");` to `f = Regex.Replace(f, "[^0-9]", "");` file did NOT = "171005_010" Almost never fails. Just have to ask before I figure it out.

(post is archived)

[–] 0 pt

Looked over my post and it hit me, you guys are cunts. Even in this post you could not resist but to try and attack my character to stroke your ego. Who the fuck said you are the software police and should try to force everyone far and wide to write code to your standard? You didn't once try and help but instead, right out of the gate, you acted like a cunt. Even now, when the question has an answer, you are still trying to get me to bend to your will. Fuck you. Cunt.