473,836 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is "CDate" a bad thing to use?

It doesnt seem to always pick up the sysem date format properly, for example
if I do CDate("19/07/2005") it seems to return an error, even though my
Regional Settigns are dd/MM/yyyy. It seems to ignore the Regional Settings
and expect US date format everytime.

What is the reccomended alternative to CDate?

Thanks!
Owen

Nov 21 '05 #1
6 11025
DateTime.Parse

"Owen" <sp**@spam.co m> wrote in message
news:Cs******** *********@newsf e1-win.ntli.net...
It doesnt seem to always pick up the sysem date format properly, for
example if I do CDate("19/07/2005") it seems to return an error, even
though my Regional Settigns are dd/MM/yyyy. It seems to ignore the
Regional Settings and expect US date format everytime.

What is the reccomended alternative to CDate?

Thanks!
Owen

Nov 21 '05 #2
"Owen" <sp**@spam.co m> schrieb
It doesnt seem to always pick up the sysem date format properly, for
example if I do CDate("19/07/2005") it seems to return an error,
even though my Regional Settigns are dd/MM/yyyy. It seems to ignore
the Regional Settings and expect US date format everytime.

Maybe the seperator is set to "." instead of "/" in the regional settings?

What is the result of CDate? Is there an exception?
What is the reccomended alternative to CDate?


CDate is recommended, but you can also use Date.Parse.

Armin
Nov 21 '05 #3
On Tue, 19 Jul 2005 13:44:02 GMT, Owen wrote:
It doesnt seem to always pick up the sysem date format properly, for example
if I do CDate("19/07/2005") it seems to return an error, even though my
Regional Settigns are dd/MM/yyyy. It seems to ignore the Regional Settings
and expect US date format everytime.

What is the reccomended alternative to CDate?

Thanks!
Owen


See the msdn help for DateTime.Parse( ) and DateTime.ParseE xact().
Nov 21 '05 #4

"Armin Zingler" <az*******@free net.de> wrote in message
news:eu******** ******@TK2MSFTN GP10.phx.gbl...
"Owen" <sp**@spam.co m> schrieb
It doesnt seem to always pick up the sysem date format properly, for
example if I do CDate("19/07/2005") it seems to return an error,
even though my Regional Settigns are dd/MM/yyyy. It seems to ignore
the Regional Settings and expect US date format everytime.

Maybe the seperator is set to "." instead of "/" in the regional settings?

What is the result of CDate? Is there an exception?

Hi Armin, I get the following exception:

Cast from string "20/07/2005 09:02:33" to type 'Date' is not valid.
Nov 21 '05 #5
"Owen" <sp**@spam.co m> schrieb
It doesnt seem to always pick up the sysem date format properly,
for example if I do CDate("19/07/2005") it seems to return an
error, even though my Regional Settigns are dd/MM/yyyy. It
seems to ignore the Regional Settings and expect US date format
everytime.

Maybe the seperator is set to "." instead of "/" in the regional
settings?

What is the result of CDate? Is there an exception?

Hi Armin, I get the following exception:

Cast from string "20/07/2005 09:02:33" to type 'Date' is not valid.

Sorry, I can't reproduce this using your regional settings. It works here.
Armin
Nov 21 '05 #6

"Armin Zingler" <az*******@free net.de> wrote in message
news:uk******** ******@TK2MSFTN GP15.phx.gbl...
"Owen" <sp**@spam.co m> schrieb
> > It doesnt seem to always pick up the sysem date format properly,
> > for example if I do CDate("19/07/2005") it seems to return an
> > error, even though my Regional Settigns are dd/MM/yyyy. It
> > seems to ignore the Regional Settings and expect US date format
> > everytime.
>
>
> Maybe the seperator is set to "." instead of "/" in the regional
> settings?
>
> What is the result of CDate? Is there an exception?

Hi Armin, I get the following exception:

Cast from string "20/07/2005 09:02:33" to type 'Date' is not valid.

Sorry, I can't reproduce this using your regional settings. It works here.


Not to worry.

I fixed the problem by editing my web.config to force the culture to "en-GB"
in the <globalizatio n> section.
Owen
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1349
by: Bjorn | last post by:
Hi, I need to determine the hightest date between e.g. "8/3/2004" and "8/4/2004". With this code, i get 'dat2' , which means that "8/4/2004" is higher than "8/3/2004". That 's right. But with "8/3/2004" and from "8/10/2004" (also "8/11/2004" ...) i get 'dat1'. <% dat1="8/3/2004"
16
10518
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am using C# eg. - String variable "strMyDate" holds the value "1/1/2005 12:00:00 AM" from the database. - I do not care about the time portion, I only want "1/1/2005" for display.
1
3379
by: stoppal | last post by:
I have the below function written in VB, and everything works fine EXCEPT that the sql code is not executing correctly. The date field is in the table always shows "12/1/1899 11:59:17 PM" no other date. I'm should have the date of the input into the function + or - the integer in the task_due_days field. for example (cdate("1/1/2002")+30) as task_due_date What am I doing wrong?
3
11741
by: Reney | last post by:
I am using Access Database in my program. The column in the table that I am going to use has date/time value with Medium Time selected. (HH:mm). The program is recording a clock in time to this field, which is the time when the entry is made. If you check the database, it shows the correct time in the correct format. But when you are calling it with a dataset and showing with a datagrid, it doesn't show the time value but it always shows...
9
1875
by: Robin Tucker | last post by:
Hiya, I need to test "relative dates" in my program, such as "last six months" or "last 3 months" or "in the last week" etc. How can I do this with a DateTime structure? ie. If NodeDate >= CurrentDate - six months (etc.)
10
4051
by: Kiran | last post by:
Hi, I am trying to convert a string(Thu Jul 21 00:00:00 UTC+0100 200) to date. I get the following error Cast from string "Thu Jul 21 00:00:00 UTC+0100 200" to type 'Date' is not valid(System.InvalidCastException) Any help on this will be appreciated
1
5951
by: melda | last post by:
I am a real beginnner in ASP. Due to increasing demands on dynamic website, I've been working on ASP website now. I use a ready to use CMS program and right now I've been trying to combine a calendar module into my CMS. The calendar works fine except that if I click on the date or the month earlier or later, the page always goes back to the first page which is first opened. You can take a look at this address:...
3
16044
by: Kosmos | last post by:
Hey ya'll...I can't seem to figure out why I'm getting this error message, but it all started when I added the new line of code with the recSet5.AddNew --- when I ran the first line, the logic worked and the fields were populated properly, when I added all the rest, it wouldn't run and even when I tried to go back, it still won't run now...I am getting the following error message: "Either BOF or EOF is True, or the current record has been...
7
4449
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am surrendered to you. <%@ Language=VBScript%> <%Option Explicit%>
0
9665
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,...
0
10835
Oralloy
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...
1
10585
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10249
tracyyun
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...
0
9367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6976
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();...
0
5645
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4447
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
3
3108
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.