Hi,
I'm trying to convert a string to date by specifying the format. The value
is like this: "03rd of April 2006". Now this is converted fine by using the
following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the
string can be 01st of..., 04th of etc., meaning that I can't use the "\r\d"
format description for all possible values.
Any suggestions? Is there a wildcard i can use, like "dd\?\?"...
Thanks,
Zsolt 11 2799
If you find no better way, try something like this:
switch (theDateTime.Da y)
{
case 1:
// use "st" here
case 2:
// use "nd" here
case 3:
// use "rd" here
default:
// use "th" here
}
Let's write a private helper for this.
Hope it helps,
Thi
Hi Thi,
Thanks for the suggestion but I would really like not to do that :).
format = new System.Globaliz ation.CultureIn fo(CultureInfo. InvariantCultur e.LCID, false);
System.DateTime DateValue = System.DateTime .ParseExact(inp utString, formatDescripti on, format);
Now the inputString is "03rd of April 2006" and the user have to tell me/system what the formatDescripti on is. It can't give me the "rd" hardcoded format, so question is if the format can be specified to cover the "st", "nd" etc cases, or we have to have something that you suggest and have to parse the format and the inputString and figure out the final format.
Regards,
Zsolt
"Truong Hong Thi" <th*****@gmail. com> wrote in message news:11******** *************@e 56g2000cwe.goog legroups.com... If you find no better way, try something like this: switch (theDateTime.Da y) { case 1: // use "st" here case 2: // use "nd" here case 3: // use "rd" here default: // use "th" here } Let's write a private helper for this. Hope it helps, Thi
zsolt wrote: Hi,
I'm trying to convert a string to date by specifying the format. The value is like this: "03rd of April 2006". Now this is converted fine by using the following format: "dd\r\d \o\f MMMM yyyy". The problem is of course that the string can be 01st of..., 04th of etc., meaning that I can't use the "\r\d" format description for all possible values.
Any suggestions? Is there a wildcard i can use, like "dd\?\?"...
It appears not. However, how about constructing a new string from the
first two characters of the input string, plus the ninth character
onwards, and then parsing that?
--
Larry Lard
Replies to group please
Hi Larry, It appears not. However, how about constructing a new string from the first two characters of the input string, plus the ninth character onwards, and then parsing that?
Yes, that is possible and it seems that it has to be done that way. The
problem is that the input format can be anything from 2006.04.03 to the
mentioned one. Because of that, I have to find out if the format is the
problematic one and make the replace/extraction or just leave it the user's
way.
It just feels strange that it's not handled easier by the framework - it's
not that unusual format. Or maybe it is :)
I don't think there is some other way. You can write another Parse
method to parse yourself. One way is trying to remove the "rd" before
parse, something like this;
DateTime ParseDateTime(s tring input)
{
string s = input.SubString (0, 2) + input.SubString (4);
// now s is "03 of April 2006", you can parse it as normal
}
It is exactly what Larry suggested.
Unfortunately yes, it seems like that. Thanks
"Truong Hong Thi" <th*****@gmail. com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.com.. . I don't think there is some other way. You can write another Parse method to parse yourself. One way is trying to remove the "rd" before parse, something like this;
DateTime ParseDateTime(s tring input) { string s = input.SubString (0, 2) + input.SubString (4); // now s is "03 of April 2006", you can parse it as normal }
It is exactly what Larry suggested.
zsolt wrote: Hi Larry,
It appears not. However, how about constructing a new string from the first two characters of the input string, plus the ninth character onwards, and then parsing that?
Yes, that is possible and it seems that it has to be done that way. The problem is that the input format can be anything from 2006.04.03 to the mentioned one. Because of that, I have to find out if the format is the problematic one and make the replace/extraction or just leave it the user's way.
It just feels strange that it's not handled easier by the framework - it's not that unusual format. Or maybe it is :)
I think I have written code in every language I have ever programmed
professionally, to produce the correct 'st' 'nd' 'th' suffix. The
Framework seems to be no exception, in that there doesn't seem to be a
way to produce these suffixes automatically; these are the only
datetime format patterns relating to days:
d The day of the month. Single-digit days will not have a leading zero.
dd The day of the month. Single-digit days will have a leading zero.
ddd The abbreviated name of the day of the week, as defined in
AbbreviatedDayN ames.
dddd The full name of the day of the week, as defined in DayNames.
If it were up to me, there would definitely be a way of producing '1st'
etc, especially as this (like many of the format patterns) depends on
culture.
--
Larry Lard
Replies to group please
Hi, Yes, that is possible and it seems that it has to be done that way. The problem is that the input format can be anything from 2006.04.03 to the mentioned one. Because of that, I have to find out if the format is the problematic one and make the replace/extraction or just leave it the user's way.
Can you control the format?
If not you have more than one problem at hand, first you have to see what
format you getting the date from , and sometimes it's difficult to know, a
good example 01/02/03 it can be viewed as 2nd of Jan 2003 ( in english) or
1st of feb ( in spanish)
It just feels strange that it's not handled easier by the framework - it's not that unusual format. Or maybe it is :)
I find the particular example weird, it's the first ime I see it
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
> Can you control the format? If not you have more than one problem at hand, first you have to see what format you getting the date from , and sometimes it's difficult to know, a good example 01/02/03 it can be viewed as 2nd of Jan 2003 ( in english) or 1st of feb ( in spanish)
Yes, the format is controled - the user is forced to describe the format.
The post is basically how to describe the "03rd of April 2006". The
"01/02/03" is easy when you know the format, the problem is only when you
try to guess the date without having format info. In my case I know the
format but can't describe it so the .NET understands it... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: G Gerard |
last post by:
Hello
I am having some problem comparing dates with the SQL statement below
MySQL = "SELECT Format(Date, 'yyyy/mmmm/dd') as FROM TblDates WHERE
_
Format(Date, 'yyyy/mmmm/dd') = #2006/April/18#"
Even though the date 2006/April/18 is in TblDates, it is never found by the
|
by: pamelafluente |
last post by:
A quick question,
I have a string with a date in european format, e.g. "30/4/2006".
What is the FASTEST way to produce the corresponding string in USA
format
"4/30/2006" and asian format "2006/4/30" ?
-pam
|
by: Robert Bravery |
last post by:
HI all,
I'm new toJS.
I am trying to get a user inputed date into mysql. The mysql database
accepts the date in yyyy-mm-dd format.
The user, from South Africa inputs the date in a web form in dd/mm/yyyy
format. Obviously when this is stored to the database table, the dates are
not quite what one would expect. I'm wantng to change the date format to
that what mysql would accept before it gets posted. I am looking for some
help with a...
|
by: mr.nimz |
last post by:
hello,
this is antenio. recently i've come to a problem. i got a way through
it, somehow, still it left me in a curious state, so i'm posting it
here, if i can get an answer from some techy,
here is my table structure,
Name: Table1
|
by: Henning M |
last post by:
Hi all,
I having some problems with Access and selecting records between dates..
When I try this in access, it works fine!!
"Select * from Bilag Where Mdates Between #1/1/2006# And #31/1/2006#"
But when I try it from my vb.net app, I get ALL the records in the tabel??
What goes wrong?
I haven't been able to find any info on the net, besides others having
| |
by: U S Contractors Offering Service A Non-profit |
last post by:
Craig Somerford
to New, Harvard, (bcc:Natural)
More options 7:56 pm (0 minutes ago)
" Working in Faith "
" SNOWING over New York City Today November 7th 2006 "
|
by: U S Contractors Offering Service A Non-profit |
last post by:
" Mentor-ship applied for November 8th 2006 "
Craig Somerford
to Harvard, Apple, Google, (bcc:Natural), (bcc:Matthew),
(bcc:National), (bcc:Letters)
Hide options 9:41 am (0 minutes ago)
From: Craig Somerford <uscos@2barter.net> Mailed-By: gmail.com
To: Harvard <rsvp@cyber.law.harvard.edu>
Cc: Apple Web Associates Post Master <postmaster@webserver.com>, Google
Maps <Google-Maps-API@googlegroups.com>
Bcc: Natural Video Church...
|
by: Petyr David |
last post by:
Just looking for the simplest. right now my perl script returns an
error messge to the user if the date string is invalid. would like to
do this before accessing the server.
TX
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |