473,811 Members | 2,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing string to datetime snafu

Before processing my data in a datagrid, I need to parse the day of the
week (which will be my 'rqsday' variable) from a string that comes over
on a querystring:

string rqs = Request.QuerySt ring["txtboardda te"];

string rqsday;

rqsday = (System.String. Format("{0:dddd }",rqs)) ;

Response.Write( rqsday);

...the variable 'txtboarddate' comes over as "7/14/2005 ) (or whatever
date the user is querying) . But I think I'm having trouble with 'rqs'
, as I can't find a way to change that to DATETIME datatype.

???
..netsports

Nov 17 '05 #1
7 7494
If the date is coming in as a string in the format of MM/DD/YYYY, simply call
DateTime.Parse( ) passing in your date string to return an actual instance of
a DateTime with that date.

Brendan
".Net Sports" wrote:
Before processing my data in a datagrid, I need to parse the day of the
week (which will be my 'rqsday' variable) from a string that comes over
on a querystring:

string rqs = Request.QuerySt ring["txtboardda te"];

string rqsday;

rqsday = (System.String. Format("{0:dddd }",rqs)) ;

Response.Write( rqsday);

...the variable 'txtboarddate' comes over as "7/14/2005 ) (or whatever
date the user is querying) . But I think I'm having trouble with 'rqs'
, as I can't find a way to change that to DATETIME datatype.

???
..netsports

Nov 17 '05 #2
Brendan, but how?
if I have
string rqs = Request.QuerySt ring["txtboardd* ate"];

and then i try rqs = DateTime.Parse( );

what am I "Parsing?" How would that be coded so I can turn it into a
datetime object so I can parse the day of the week from it

Nov 17 '05 #3
You would actually change the types you are using, instead of rsqday being a
string, you use it as a DateTime and have it reference the result of the
DateTime.Parse( ) of rsq ala:

string rqs = Request.QuerySt ring["txtboardda te"];

DateTime rqsday;

rqsday = DateTime.Parse( rsq);

Response.Write( rqsday.ToString ());
What you are doing is having the DateTime class parse the string you
returned from the database to determine the date that the string represents.

Brendan
".Net Sports" wrote:
Brendan, but how?
if I have
string rqs = Request.QuerySt ring["txtboarddÂ*ate "];

and then i try rqs = DateTime.Parse( );

what am I "Parsing?" How would that be coded so I can turn it into a
datetime object so I can parse the day of the week from it

Nov 17 '05 #4
Thanks for helping - still, I need to make rqsday into a string that
contains "Friday" or "Thursday" ( whatever day that the 'rqs' falls on)
..
Doing this:
string rqs = Request.QuerySt ring["txtboardd* ate"];
DateTime rqsday;
rqsday = DateTime.Parse( rsq);
rqsday = rqsday.ToString ("{dddd}");

...I still get the Build error pointing to the last line rqsday =
rqsday.ToString ("{dddd}");
the "cannot implicitly convert type 'string' to 'System.DateTim e' error

????
..netsports

Nov 17 '05 #5
So what you are looking for is the day of the week that the date returned
from Request.QuerySt ring["txtboardda te"]? Ahh, I thought you were looking for
the full DateTime class. In either case, take the following code...

string dayOfWeek;
string rqs = Request.QuerySt ring["txtboardda te"];
DateTime rqsday;
rqsday = DateTime.Parse( rqs);
dayOfWeek = rqsday.DayOfWee k.ToString();

One little note, I seem to have had a typo in the last code I gave you in
which rsq was being passed into DateTime.Parse( ), that has been fixed now.

Anyway, here we get the string representing the actual date (ie 7/15/2005),
then have it parsed into an instance of the DateTime class, and finally read
the DayOfWeek property from that instance to determine the actual day of the
week, all without the need for the dddd format conversion to string. If
however you want to use that... you can simply change the associated line to:

dayOfWeek = rqsday.ToString ("dddd");

or the following if you want the {} chars to be part of the output:

dayOfWeek = rqsday.ToString ("{dddd}");

Remember though, that in either case a String is being returned so you
should be sure to store it in such a variable type, unlike the code you
replied with where you are attempting to store that string in rqsday which
has been changed to be a string, rather than a DateTime.

Brendan
".Net Sports" wrote:
Thanks for helping - still, I need to make rqsday into a string that
contains "Friday" or "Thursday" ( whatever day that the 'rqs' falls on)
..
Doing this:
string rqs = Request.QuerySt ring["txtboarddÂ*ate "];
DateTime rqsday;
rqsday = DateTime.Parse( rsq);
rqsday = rqsday.ToString ("{dddd}");

...I still get the Build error pointing to the last line rqsday =
rqsday.ToString ("{dddd}");
the "cannot implicitly convert type 'string' to 'System.DateTim e' error

????
..netsports

Nov 17 '05 #6
Yep, that's it Brendan, much thanks for your help and explanations!

Nov 17 '05 #7
..Net Sports <ba********@cox .net> wrote:
Thanks for helping - still, I need to make rqsday into a string that
contains "Friday" or "Thursday" ( whatever day that the 'rqs' falls on)
.
Doing this:
string rqs = Request.QuerySt ring["txtboardd* ate"];
DateTime rqsday;
rqsday = DateTime.Parse( rsq);
rqsday = rqsday.ToString ("{dddd}");

..I still get the Build error pointing to the last line rqsday =
rqsday.ToString ("{dddd}");
the "cannot implicitly convert type 'string' to 'System.DateTim e' error

????
.netsports


Firstly, if you call DateTime.ToStri ng, that takes *just* a format
string, rather than a full string which *includes* a format string. In
other words, you want ToString("dddd" ) rather than ToString("{dddd }")

Secondly, you're trying to assign the formatted string to rqsday, which
is a DateTime. You need to use a string variable, eg rqs, instead.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #8

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

Similar topics

2
1602
by: msnews.microsoft.com | last post by:
Does the framework support the changing of a files Date and Time and if so is there sample could for which I can be directed?
2
2672
by: .Net Sports | last post by:
I'm using these to assign a variable to a smalldatetime object in sql server: dim todnews = DateTime.Today.ToString ( "d" ) 'connection string to server is on this line Dim strSQL2 as string ="SELECT Arrived,Title,ID,story FROM tblGeneral WHERE Arrived = 'todnews'" ...but I get a syntax error saying i can't change a string to smalldatetime data type. When I try replacing DateTime.Today.ToString (
4
1329
by: Robert Dobson | last post by:
I've run into a rather perplexing problem and unfortunately nobody has yet been able to help me resolve it. I have built an application that supports both English and Spanish text. When I compile, I get /bin/snafu.dll and /bin/es-MX/snafu.resources.dll. When I run it on my workstation, everything is fine; I can see both the English and Spanish versions. However, when I copy the application to another machine, I can no longer see the...
5
1639
by: Terry Olsen | last post by:
I have a function that returns the date in the following format: 6/22/2005 I need the format to be: 050622 I have zero experience with RegEx but I believe that would be the way to go here. Can someone give me some info on this? Or if RegEx isn't the way,
20
35646
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the project the date format in vb.code ( not in Windows) and how can I find out which date format the PC Windows is using. Thanks for any response
7
35707
by: billygotee | last post by:
Hi, Okay this is taking longer to figure out than I thought it would. The integer members of a DateTime (such as DateTime.Minutes, DateTime.Seconds, etc.) can only get the value, not set it. Is there a way to set one of these without parsing a string? What I want to do is clear out the Minutes, Seconds, and Milliseconds values so that the smallest resolution allowed in the DateTime (for my application) is an hour. Any method of...
2
1666
by: almurph | last post by:
Hi, Hope that you can help me with this. I'm calling DateTime.Now and storing in a DateTime container. I see that the pattern format is: m/ dd/yyyy I need it to be in the format: yyyy-MM-dd HH:MM:SS as type DateTime but I don't know how to do this! Can anyone help me please? Any comments/advice/suggestions/code-sampels much appreciate.
0
848
by: CreativeMind | last post by:
hi all, i m using these lines of code in my program. but when i deploy , the live server machine doesn't change date format. IFormatProvider culture=new CultureInfo("en-GB",true); string a=string.Empty; DateTime FromEntryDate=Convert.ToDateTime("01/01/1900"); if( txtStartEntryDate.Text.Trim()!=""){
2
2626
by: akronymn | last post by:
I have an mssql database that I need to migrate to mysql. For some reason though any queries to any columns of type datetime are returned in French in the following format: 7/avr/2004 14:00 This also includes all the text of an SQL dump which not surprisingly makes mysql unable to read the dump from the MSSQL db. I've checked that my windows regional setting is set to English. I'm at a loss as to why this is happening or how to fix it. I...
0
9728
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10389
jinu1996
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...
1
10402
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
10135
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
9205
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
6890
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
5554
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
4339
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
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.