Keep in mind we have no other information than what you explicitely tell us to understand what you are trying to do. For now it seems something you can easily do out of the box.
Or finally if you tried something and it fails, it could be easier to tell which problem you are trying to solve...
Like below which i have created for left . Can we see the code of existing Day function
Public Function myLeft(ByVal sourceStr As String, ByVal noOfChars As Integer) As String
If sourceStr.Length = 0 Or noOfChars < 0 Then Return ""
If sourceStr.Length <= noOfChars Then Return sourceStr
sourceStr = Microsoft.VisualBasic.Left(sourceStr, noOfChars)
Return sourceStr
End Function
It's best to work on "native data" as much as possible ie a date should be converted to a string just before shown to users and the string input should be converted to a date before further processing. Even with web forms you could use something such as https://docs.microsoft.com/en-us/aspnet/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data the
data to string or string to data conversion being handled for you based on the current culture and specific information you can add on properties.
You have a form with an date input field ? You are using a datepicker or a text input field ? Your site supports a single "language" (which one ?)
More information about tryparse() method you can use
ilspy tool to view the source code.
Best Regard,
Sam
IIS.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
140 Points
515 Posts
Custom Functions
Aug 10, 2019 09:43 AM|jsshivalik|LINK
Hi
How we can create our own custom functions for day & Format
Thanks
All-Star
48730 Points
18189 Posts
Re: Custom Functions
Aug 10, 2019 09:58 AM|PatriceSc|LINK
Hi,
Some more context could help. Do you mean you don't have for date formatting, any culture that fit your needs ? You can create a custom culture https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureandregioninfobuilder?view=netframework-4.8 or a custom https://docs.microsoft.com/en-us/dotnet/api/system.iformatprovider?view=netframework-4.8 but for now I believe you perhaps not explored yet what is available out of the box or you lack direction about handling this ?
Member
140 Points
515 Posts
Re: Custom Functions
Aug 10, 2019 10:20 AM|jsshivalik|LINK
Hi Patrice
Can u pls suggest on to find day,month,year using own custom function .
Thanks
All-Star
53721 Points
24046 Posts
Re: Custom Functions
Aug 10, 2019 10:50 AM|mgebhard|LINK
Your question is too vague to answer.
See the official DateTime format functions if you need to display a date in a specific format.
https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
The DateTime structure has methods and properties that return the day, month, and year. Again, please try reading the official documentation.
https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=netframework-4.8
If you want a forum member to review your code then you'll need to share the custom function. Explain the expected results and the actual results.
All-Star
48730 Points
18189 Posts
Re: Custom Functions
Aug 10, 2019 12:27 PM|PatriceSc|LINK
I still don't get what you mean. If you have a valid DateTime just look at its properties ie https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=netframework-4.8#properties (Day, Month and Year properties). Why would you need custom functions ?
If you need to convert a string to a DateTime it can depend on the current "culture" you could define in the web.config file using https://documentation.devexpress.com/AspNet/12062/Localization/How-to-Set-a-Culture-for-an-ASP-NET-Web-Page
Keep in mind we have no other information than what you explicitely tell us to understand what you are trying to do. For now it seems something you can easily do out of the box.
Or finally if you tried something and it fails, it could be easier to tell which problem you are trying to solve...
Member
140 Points
515 Posts
Re: Custom Functions
Aug 10, 2019 02:00 PM|jsshivalik|LINK
Hi PatricSc
Like below which i have created for left . Can we see the code of existing Day function
Public Function myLeft(ByVal sourceStr As String, ByVal noOfChars As Integer) As String
If sourceStr.Length = 0 Or noOfChars < 0 Then Return ""
If sourceStr.Length <= noOfChars Then Return sourceStr
sourceStr = Microsoft.VisualBasic.Left(sourceStr, noOfChars)
Return sourceStr
End Function
Thanks
All-Star
48730 Points
18189 Posts
Re: Custom Functions
Aug 10, 2019 06:34 PM|PatriceSc|LINK
It's best to work on "native data" as much as possible ie a date should be converted to a string just before shown to users and the string input should be converted to a date before further processing. Even with web forms you could use something such as https://docs.microsoft.com/en-us/aspnet/web-forms/overview/presenting-and-managing-data/model-binding/retrieving-data the data to string or string to data conversion being handled for you based on the current culture and specific information you can add on properties.
You have a form with an date input field ? You are using a datepicker or a text input field ? Your site supports a single "language" (which one ?)
Contributor
3370 Points
1409 Posts
Re: Custom Functions
Aug 12, 2019 08:31 AM|samwu|LINK
Hi jsshivalik,
Do you mean you want to create a function that converts dates?
If so, you can try below code(base on DataTime source code):
The first parameter is the string to determine whether its length is 0 and the value is null.
The second parameter is culture-specific information about the format of date and time values.
The third parameter define the formatting options that customize string parsing for some date and time parsing methods.
The fourth parameter is the result returned.
More information about tryparse() method you can use ilspy tool to view the source code.
Best Regard,
Sam