Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I found a regular expression for the Persian Calendar in the link but it is in the yyyy/MM/dd format. Any suggestion to format to dd/MM/yyyy and MM/dd/yyyy?
(?:1[234]\d{2})(\/|\-)(?:0?[1-9]|1[0-2])(\/|\-)(?:0?[1-9]|[12][0-9]|3[01])$
Debuggex Demo
support year between 1200 and 1499
I am using this code and it works well:
First you define a constant like the following code:
public const string PersianDateRegex = #"(?:1[23]\d{2})\/(?:0?[1-9]|1[0-2])\/(?:0?[1-9]|[12][0-9]|3[01])$";
so for test it you can use the below code:
if (Regex.IsMatch(farsiDate, PersianDateRegex))
{
...
}
Try this in ASP.NET MVC for validation of a Persian date:
[RegularExpression(#"^$|^([1۱][۰-۹ 0-9]{3}[/\/]([0 ۰][۱-۶ 1-6])[/\/]([0 ۰][۱-۹ 1-9]|[۱۲12][۰-۹ 0-9]|[3۳][01۰۱])|[1۱][۰-۹ 0-9]{3}[/\/]([۰0][۷-۹ 7-9]|[1۱][۰۱۲012])[/\/]([۰0][1-9 ۱-۹]|[12۱۲][0-9 ۰-۹]|(30|۳۰)))$", ErrorMessage = "Not Valid")]
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
(so it looks like this "15.05-2019")but I don't want to remove the dot or the dash.How do I do this in C#
You could parse it to a DateTime and then format it back.
var result = DateTime.ParseExact("15.May-2019", "dd.MMMM-yyyy", System.Globalization.CultureInfo.InvariantCulture)
.ToString("dd.MM-yyyy");
This is useful if you need to handle dates with any month in them.
Note that the MMMM will work for long month names, but if you're dealing with short names MMM would be the way to go (for May the short and long names are the same). You can also use the overload of ParseExact that takes multiple formats if you need to handle both.
var str = "15.May-2019";
str = str.Replace("May", "05")
To replace part of a string you can do:
var date = "15.05-2019";
date = date.Replace("05", "May");
Console.WriteLine(date);
output : "15.May-2019"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a C# program that communicates with MySql database and I want to write current time to database column defined as TIME. Now, when I run my program the time that has been written is for example 00:00:19 and not for example 19:34:00. Why this happens and how can I solve this?
Thanks in advance
SOLUTION
This solved the problem:
DateTime.Now.ToString("yyyyMMddHHmmss")
this because the format mysql : "yyyy-MM-dd hh:mm:ss"
check the format in you programme or try to insert a String like this "2016-23-08 13:00:00"
I think the problem caused by dateTimeVariable.ToString() method of your DateTime value.
To solve this problem use dateTimeVariable.ToString("s") to convert the DateTime to standard DateTime string.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have to validate a sting with regular expression.
String Should be in the NHCC-XXXXX-00 Format ,where X is a Number.
Correct strings:
NHCC-10010-00,
NHCC-78965-00,
NHCC-99654-00
Wrong strings:
NHCC-1001-00
NHCC-78965-0
NHC-99654-00
ASDF-99654-00
NHCC-F9654-00
NHCC-99654-01
Can any one help me to solve the above senario?
This should work:
"NHCC-\d{5}-00"
Demo
You need to use anchors inorder to do an exact match.
#"^NHCC-\d{5}-00$"
The regular expression you want is #"(?s)^NHCC-\d{5}-00$"
if (!Regex.IsMatch(input, #"(?s)^NHCC-\d{5}-00$"))
{
//not valid
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Can you advice me, how solve the problem
I need get date from string.
For example:
Dear client come to our shop 20.08.2014 10:20 other text
or
Dear client come to our shop 20 august 2014 10:20 other text
Thanks.
Simply use the date pattern to extract it from the string
\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}
Here is online demo
For second pattern use
\d{2} (january|february|march|...) \d{4} \d{2}:\d{2}
I think you need to implement your custom implementation as ypur requirements is very different.
use c# built-in functions and implement your logic
String.IndexOf (http://msdn.microsoft.com/en-us/library/k8b1470s(v=vs.110).aspx)
String.Substring (http://msdn.microsoft.com/en-us/library/hxthx5h6(v=vs.110).aspx)
Note: Handle 12 months 30 days and an year with there different formats and get the substring based on that.
Try to use:
(?i)\d{1,2}\s*\.?\s*(?:\d{1,2}|January|February|March|April|May|June|July|August|September|October|November|December)\s*\.?\s*\d{2,4}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a string "5-13-2013"
I want to make it look like "051313"
All three fields (month,day,year) must have 2 digits, if it only has one , I need to add a zero in front
any easy way to do this?
You can convert your datetime to multiple formats like
string date = yourdateTime.ToString("dd/mm/yyyy");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm");
string date = yourdateTime.ToString("dd/mm/yyyy HH:mm:ss");
string date = yourdateTime.ToString("mmddyy"); // your desired
To know what these mean you need to read here.