473,785 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a question regarding DateTime

Hey

..NET 2.0

I'm about to create 2 input parameters for a method. These are 2 DateTime
parameters - one named "from" and another named "to"... - from and to
DateTime values...

Okay the trick is that the "from" DateTime should be like this
01.<MM>.<YYYY ss:mm.hh which means that today is the 03.12.2007 then the
"from" date should be 01.12.2007 00:00:00. What is the best way of
calculating this?

any suggestions?
Dec 3 '07
10 1496
In article <Ov************ **@TK2MSFTNGP02 .phx.gbl>,
Liz <li*@tiredofspa m.comwrote:
"Lasse Vågsæther Karlsen" <la***@vkarlsen .nowrote in message
Liz wrote:
so you want the current month.year, always prefixed with "01" and
postfixed with "00:00:00" .. ? this should work:

DateTime dt = DateTime.Now;
string t = "01." + dt.Month.ToStri ng().PadLeft(2, '0') + "." +
dt.Year.ToStrin g() + " 00:00:00";
DateTime dt2 = Convert.ToDateT ime(t);
don't know if it's the "best" way ... it's a way ...

That's what I call a solutionproblem , a solution with more problems than
it solves.

Go with the way that Jon posted.

I had not seen Jon's solution; now that I have, no doubt it's cleaner and I
would use it; compared to his, I see awkward, not problematic .. it does
work ... what "problems" do you see with this one other than it's slower and
more verbose?
Cultural info would be my guess...plus unnecessary code (there's no
reason to do the padding or add the time part).
If you're going to do a string conversion, then...

DateTime dt2 = DateTime.Parse( DateTime.Now.To String("yyyy/MM/01"));

But Jon's method (using new DateTime) is better as it avoids string
parsing entirely, and is thus more readable and probably faster.

--
J.B. Moreno
Dec 19 '07 #11

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

Similar topics

4
2530
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it should be used? I can make a datetime easily enough
15
14289
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" DateTime.Now.AddMinutes(90) returns "1:30" or "01:30"
6
8991
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference between date and datetime classes? Please, help
11
7253
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why only that I have to listen to them because they know it better. They told also that in a business situation it is better to use datetime.parseexact for changing cultures and not to use the globalization setting. I did not give them this sample,...
9
4929
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="urn:JadeWebServices/WebServiceProvider/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
0
856
by: Striker | last post by:
Hello All I am using asp.net(vbscripts) and sqlserver I am having a problem regarding time comparison, In my application a from field submits datetime in sqlsever database field, now what i need is that to compare that inserted (time only part of the database field) with the new datetime form field record and if the value of the new record is less in time than the value in the database then, i have to submit a new record in the database,...
4
1604
by: bsonline | last post by:
I hv a datetime format like '24/01/2008 15:56:01' . Now I have to select dates from a date range, but input datetime format like 24/1/2008 15:56:01'. I hv written the query like : "select date_column from date_table where to_char(date_column,'dd/mm/yyyy hh24:mi:ss') between input_date and input_date; " here I face a problem that when the date range within a month, it works fine. but when it become greater may be 2 or 6 month date range...
0
16510
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
1
2325
by: subhalalitha | last post by:
There is a requirement in our system. There is one Transaction Monitoring thread which wakes up after every 30 sec and checks for the requests that didnot get responses for "2 min" and sends Timeout Responses to the caller. There is a need to wake up this Thread upon an "event" to send Timeout responses for all the Requests. I tried samples and this combination does not seem to work for me. In short , The thread should wake up...
0
9480
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
10319
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
10087
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
8971
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...
1
7496
isladogs
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...
0
6737
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4046
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
3645
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.