PC Review


Reply
Thread Tools Rate Thread

dateTime Manupulations

 
 
Reny J Joseph Thuthikattu
Guest
Posts: n/a
 
      20th Oct 2004
Hi,
I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
miniute to it.How can i do that?
by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
12:00 AM'
How do i do that?
Reny


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.779 / Virus Database: 526 - Release Date: 19/10/04


 
Reply With Quote
 
 
 
 
Shiva
Guest
Posts: n/a
 
      20th Oct 2004
Convert the date/time string to DateTime type using DateTime.ParseExact()
and then call .AddMinutes(1).

HTH.

"Reny J Joseph Thuthikattu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hi,
I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
miniute to it.How can i do that?
by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
12:00 AM'
How do i do that?
Reny


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.779 / Virus Database: 526 - Release Date: 19/10/04



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Oct 2004
Renny,

This sample should do it

\\\
Public Class Main
Public Shared Sub Main()
Threading.Thread.CurrentThread.CurrentCulture = _
New Globalization.CultureInfo("en-AU")
'When you are not in the culture with this settingtis

MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
'The above row is the only thing what is needed when it is in your own
culture setting

'And set the culture back when it was not your own culture
Threading.Thread.CurrentThread.CurrentCulture = _
Globalization.CultureInfo.InstalledUICulture
End Sub
End Class
///

I hope this helps?

Cor



"Reny J Joseph Thuthikattu"
> Hi,
> I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
> miniute to it.How can i do that?
> by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
> 12:00 AM'
> How do i do that?
> Reny



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Oct 2004
Doh,

> MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)

MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").Addminutes(1).ToString)

Of course

Cor


"Cor Ligthert" <(E-Mail Removed)>

> Renny,
>
> This sample should do it
>
> \\\
> Public Class Main
> Public Shared Sub Main()
> Threading.Thread.CurrentThread.CurrentCulture = _
> New Globalization.CultureInfo("en-AU")
> 'When you are not in the culture with this settingtis
>
> MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
> 'The above row is the only thing what is needed when it is in your own
> culture setting
>
> 'And set the culture back when it was not your own culture
> Threading.Thread.CurrentThread.CurrentCulture = _
> Globalization.CultureInfo.InstalledUICulture
> End Sub
> End Class
> ///
>
> I hope this helps?
>
> Cor
>
>
>
> "Reny J Joseph Thuthikattu"
>> Hi,
>> I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add
>> a
>> miniute to it.How can i do that?
>> by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
>> 12:00 AM'
>> How do i do that?
>> Reny

>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      20th Oct 2004
Cor,
Just curious why are you resetting the CurrentCulture to InstalledUICulture?

Why are you arbitrarily picking a Culture to get a specific date format?

Wouldn't using DateTime.ParseExact be better? In that you can specify a
specific format, plus you don't run the risk of resetting CurrentCulture
that may have been explicitly been set to something other then
InstalledUICulture elsewhere in your program?

Honestly, I am sincerely interested in knowing what you don't understand
about DateTime.ParseExact?

Using DateTime.ParseExact would be:

Const format As String = "dd-MMMM-yyyy hh:mm tt"
Dim s As String = "01-JUNE-2004 11:59 PM"

Dim d As DateTime = DateTime.ParseExact(s, format, Nothing)

Notice that its a single line & there is no chance of changing the
CurrentCulture that may have explicity been set elsewhere in the program.

Just curious
Jay

"Cor Ligthert" <(E-Mail Removed)> wrote in message
news:OF%(E-Mail Removed)...
> Renny,
>
> This sample should do it
>
> \\\
> Public Class Main
> Public Shared Sub Main()
> Threading.Thread.CurrentThread.CurrentCulture = _
> New Globalization.CultureInfo("en-AU")
> 'When you are not in the culture with this settingtis
>
> MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
> 'The above row is the only thing what is needed when it is in your own
> culture setting
>
> 'And set the culture back when it was not your own culture
> Threading.Thread.CurrentThread.CurrentCulture = _
> Globalization.CultureInfo.InstalledUICulture
> End Sub
> End Class
> ///
>
> I hope this helps?
>
> Cor
>
>
>
> "Reny J Joseph Thuthikattu"
>> Hi,
>> I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add
>> a
>> miniute to it.How can i do that?
>> by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
>> 12:00 AM'
>> How do i do that?
>> Reny

>
>



 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      20th Oct 2004
Reny,
Is your variable a string or DateTime variable?

Do you want help converting a date from a string, is your date in a specific
format or is that how Windows Formats your dates?

Am I reading your message correctly, you want to round a date up to the next
day?

I would use something like:
Dim s As String = "01-JUNE-2004 11:59 AM"

' converts a string in a specific
Const format As String = "dd-MMMM-yyyy hh:mm tt"
Dim d As DateTime = DateTime.ParseExact(s, format, Nothing)

Dim noon As TimeSpan = TimeSpan.FromHours(12)

' Rounds a date to the nearest day
If d.TimeOfDay.CompareTo(noon) > 0 Then
d = d.Date.AddDays(1)
Else
d = d.Date
End If

Debug.WriteLine(d.ToLongDateString())
Debug.WriteLine(d.ToLongTimeString())



For details on custom datetime formats see:

http://msdn.microsoft.com/library/de...matstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/de...ttingtypes.asp

Hope this helps
Jay

"Reny J Joseph Thuthikattu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a
> miniute to it.How can i do that?
> by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
> 12:00 AM'
> How do i do that?
> Reny
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.779 / Virus Database: 526 - Release Date: 19/10/04
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Oct 2004
"Cor Ligthert" <(E-Mail Removed)> schrieb:
> Threading.Thread.CurrentThread.CurrentCulture = _
> New Globalization.CultureInfo("en-AU")
> [...]
> 'And set the culture back when it was not your own culture
> Threading.Thread.CurrentThread.CurrentCulture = _
> Globalization.CultureInfo.InstalledUICulture


It seems that you missed Jon Skeet's comment about this code in the previous
thread...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Oct 2004
Jay,

I just following the advice from the VBNet pages to use the Convert
Functions from which I understand it is advices to use them because they
give the best overall performance.

Although when those advices were not given do I find them very clear to use
and easy. I find them one of the best extra parts of VBNet.

Because of all that doing, from Herfried and others who say that when
someone who asks how to set a date and time, and than gives with that a
format string, particulary wants to use change a format not in his own
local format I give now that other situation.

In my opinion are those datestring information more given as extra
information for us (what format the OP is using) than that he directly wants
to convert the format. I did not by accident give the Australian format when
I saw the time of the message. However that was a gues.

Beside that can I only think of one situation where it is needed to change
the dateandtime given in a culture and that is with a webformpage or with
any other document where that is in.

Than it is better in my opinion to set in the class that processes that
first the right language/culture and set that back at the end of the class.
Doing that for every instruction inside will give in my idea more dangerous
code when there is maintanance.

That has nothing to do with understanding. Sometimes I get the idea that you
think that I write things because of lack of knowledge.

For me are rules as 80/20 and "keep it simple" very important. A program
have to be made however mostly as well will there be maintenance on it.

I hope that you can share my opinion above and understand why I am telling
this about globalization.

Cor


"Jay B. Harlow [MVP - Outlook]" <(E-Mail Removed)>

> Cor,
> Just curious why are you resetting the CurrentCulture to
> InstalledUICulture?
>
> Why are you arbitrarily picking a Culture to get a specific date format?
>
> Wouldn't using DateTime.ParseExact be better? In that you can specify a
> specific format, plus you don't run the risk of resetting CurrentCulture
> that may have been explicitly been set to something other then
> InstalledUICulture elsewhere in your program?
>
> Honestly, I am sincerely interested in knowing what you don't understand
> about DateTime.ParseExact?
>
> Using DateTime.ParseExact would be:
>
> Const format As String = "dd-MMMM-yyyy hh:mm tt"
> Dim s As String = "01-JUNE-2004 11:59 PM"
>
> Dim d As DateTime = DateTime.ParseExact(s, format, Nothing)
>
> Notice that its a single line & there is no chance of changing the
> CurrentCulture that may have explicity been set elsewhere in the program.
>
> Just curious
> Jay
>
> "Cor Ligthert" <(E-Mail Removed)> wrote in message
> news:OF%(E-Mail Removed)...
>> Renny,
>>
>> This sample should do it
>>
>> \\\
>> Public Class Main
>> Public Shared Sub Main()
>> Threading.Thread.CurrentThread.CurrentCulture = _
>> New Globalization.CultureInfo("en-AU")
>> 'When you are not in the culture with this settingtis
>>
>> MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
>> 'The above row is the only thing what is needed when it is in your
>> own
>> culture setting
>>
>> 'And set the culture back when it was not your own culture
>> Threading.Thread.CurrentThread.CurrentCulture = _
>> Globalization.CultureInfo.InstalledUICulture
>> End Sub
>> End Class
>> ///
>>
>> I hope this helps?
>>
>> Cor
>>
>>
>>
>> "Reny J Joseph Thuthikattu"
>>> Hi,
>>> I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add
>>> a
>>> miniute to it.How can i do that?
>>> by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004
>>> 12:00 AM'
>>> How do i do that?
>>> Reny

>>
>>

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      20th Oct 2004
Herfried,

The mainpart of the message was.

MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
'The above row is the only thing what is needed when it is in your own
culture setting

Please do not express misquote me what this is obvious

I see that as abuse.

Cor


 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      20th Oct 2004
"Cor Ligthert" <(E-Mail Removed)> schrieb:
> The mainpart of the message was.
>
> MessageBox.Show(CDate("01-JUNE-2004 11:59 PM").AddDays(1).ToString)
> 'The above row is the only thing what is needed when it is in your own
> culture setting


This doesn't make it work better.

> Please do not express misquote me what this is obvious


I didn't misquote anything.

> I see that as abuse.


I don't know if you are ignorant or just don't understand it.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
build Dictionary< DateTime , decimal > from List < DateTime > John A Grandy Microsoft C# .NET 1 5th Feb 2009 03:08 AM
Millisecond values missing when inserting datetime into datetime column of sql Server Manikandan Microsoft C# .NET 4 18th Jul 2007 08:59 PM
How can I save a DateTime from my C# program into a SQL Server (datetime) database column. Steve Kershaw Microsoft ASP .NET 5 29th Aug 2006 03:10 AM
Re: converting Unix datetime count to .Net DateTime object Mark Worrall Microsoft C# .NET 1 4th Feb 2004 07:29 AM
XML dateTime conversion to DateTime.MinValue accross timezones Symon R Microsoft Dot NET 0 6th Aug 2003 07:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:56 AM.