473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Why is this formatted result one day off?

Ok, the 'SecondDate' comes from sql server, but I wanted to make it
visible here...but no matter what day I get in SecondDate, it comes up
one day off every time...the hours minutes and seconds are right:

Dim SecondDate As Date = "2/28/04 10:50:00 PM"
Dim FirstDate As Date
FirstDate = CDate(SecondDate)
Dim secs As Long = DateDiff(DateInterval.Second, Now,
SecondDate)
Dim dt As New DateTime(secs * 10000000D)
Dim dte As StreamWriter
dte = New StreamWriter("D:\datetimetest.txt", True)
dte.WriteLine(dt.ToString("dd HH:mm:ss"))
dte.Close()
Response.Write(dt.ToString("dd HH:mm:ss"))

Any help is greatly appreciated.
Thanks,
Trint

..Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
9 866
Trint,

Somebody else may reply with the answer but meanwhile...

What's all the extra "stuff" for? If you don't need the StreamWriter in
order to demonstrate your problem it is much simpler for everybody if you
eliminate it as a source of your problem. I'm just scanning the code
quickly but what is FirstDate for? Why is it that you are casting
SecondDate (a date) to a Date isn't it already a date?

I don't even see what is "off" about it... what answer are you getting and
why do believe it isn't right?
"Trint Smith" <tr********@hotmail.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
Ok, the 'SecondDate' comes from sql server, but I wanted to make it
visible here...but no matter what day I get in SecondDate, it comes up
one day off every time...the hours minutes and seconds are right:

Dim SecondDate As Date = "2/28/04 10:50:00 PM"
Dim FirstDate As Date
FirstDate = CDate(SecondDate)
Dim secs As Long = DateDiff(DateInterval.Second, Now,
SecondDate)
Dim dt As New DateTime(secs * 10000000D)
Dim dte As StreamWriter
dte = New StreamWriter("D:\datetimetest.txt", True)
dte.WriteLine(dt.ToString("dd HH:mm:ss"))
dte.Close()
Response.Write(dt.ToString("dd HH:mm:ss"))

Any help is greatly appreciated.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Cor
Hi Trint,

Have a look at this, this is something as a sample that is very much near
what you need I think.

Module main
Public Sub main()
Dim starttime As DateTime = DateTime.Now
starttime = starttime.AddSeconds(10)
Dim span As TimeSpan = starttime.Subtract(Now)
Do While starttime > Now
MessageBox.Show(span.ToString)
Threading.Thread.Sleep(1000)
span = starttime.Subtract(Now)
Loop
End Sub
End Module

I hope this helps a little bit?

Cor
Nov 20 '05 #3
Cor,
I tried that with a little modification to my needs and the other is
still closer to what I need...here's why:
All I need is the 'time left: dd HH:mm:ss'.
ending datetime "2/28/04 10:50:00 PM" <-any future datetime
and NOW. The method of visual countdown on the screen will have to be
done by flash or java once I have this value.
Thanks,
Trint

.Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Trint,
I would use Integer (Long) arithmetic here instead of Decimal (does not
change result).
Dim dt As New DateTime(secs * 10000000D) Dim dt As New DateTime(secs * 10000000L)
What exactly are you attempting to do? Based on what your example prints, I
would think a TimeSpan would work better.

Something like:
Dim secondDate As Date = "2/28/04 10:50:00 PM"
Dim firstDate As Date = DateTime.Now

Dim secs As Long = DateDiff(DateInterval.Second, firstDate,
secondDate)
Dim dt As New DateTime(secs * 10000000L)
Debug.WriteLine(dt.ToString("dd HH:mm:ss"), "DateDiff")

Dim ts As TimeSpan = secondDate.Subtract(firstDate)
Debug.WriteLine(String.Format("{0:D2} {1:D2}:{2:D2}:{3:D2}",
ts.Days, ts.Hours, ts.Minutes, ts.Seconds), "TimeSpan")

Unless of course you are expecting 10 instead of 8, then my example also has
an "issue" ;-)

Hope this helps
Jay
"Trint Smith" <tr********@hotmail.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl... Ok, the 'SecondDate' comes from sql server, but I wanted to make it
visible here...but no matter what day I get in SecondDate, it comes up
one day off every time...the hours minutes and seconds are right:

Dim SecondDate As Date = "2/28/04 10:50:00 PM"
Dim FirstDate As Date
FirstDate = CDate(SecondDate)
Dim secs As Long = DateDiff(DateInterval.Second, Now,
SecondDate)
Dim dt As New DateTime(secs * 10000000D)
Dim dte As StreamWriter
dte = New StreamWriter("D:\datetimetest.txt", True)
dte.WriteLine(dt.ToString("dd HH:mm:ss"))
dte.Close()
Response.Write(dt.ToString("dd HH:mm:ss"))

Any help is greatly appreciated.
Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #5
This is it for those following this:

Dim SecondDate As Date = "2/28/04 09:12:00 PM"
Dim FirstDate As Date = Now
Dim secs As Long = DateDiff(DateInterval.Second, Now,
SecondDate)

Dim ts As TimeSpan = TimeSpan.FromSeconds(secs)
Response.Write(ts.Days.ToString() & "d:" & ts.Hours.ToString() &
"h:" & ts.Minutes.ToString() & "m:" & ts.Seconds.ToString() & "s")

Thanks,
Trint

..Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
Trint,
Why bother with the DateDiff function at all????
Dim SecondDate As Date = "2/28/04 09:12:00 PM" Dim ts As TimeSpan = SecondDate.Subtract(Now) Response.Write(ts.Days.ToString() & "d:" & ts.Hours.ToString() &
"h:" & ts.Minutes.ToString() & "m:" & ts.Seconds.ToString() & "s")
I don't really see that it (DateDiff) is adding any *value* to your
function, if any thing its making your function longer (and slower) then it
needs to be...

Hope this helps
Jay

"Trint Smith" <tr********@hotmail.com> wrote in message
news:ua**************@tk2msftngp13.phx.gbl... This is it for those following this:

Dim SecondDate As Date = "2/28/04 09:12:00 PM"
Dim FirstDate As Date = Now
Dim secs As Long = DateDiff(DateInterval.Second, Now,
SecondDate)

Dim ts As TimeSpan = TimeSpan.FromSeconds(secs)
Response.Write(ts.Days.ToString() & "d:" & ts.Hours.ToString() &
"h:" & ts.Minutes.ToString() & "m:" & ts.Seconds.ToString() & "s")

Thanks,
Trint

Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #7
Jay,
All I want is the time remaining and this was the only way I could
figure out that would do it.

Beginning DateTime:
Doesn't Matter

Ending DateTime:
2/28/04 09:12:00 PM

Now:
2/20/2004 11:26:49 AM

This comes from Diff and is what I needed:
Time Remaining:
8d:9h:45m:10s

Thanks,
Trint

..Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #8
Cor
Hi Trint,

You give me really the idea that you not are looking to the help you get.

CJ was helping you and I was reading it, I got an idea from that, that I
would try.

Yesterday I made completly the routine that you wanted for a aspx server
application (although not complete, the bitmap is still to hugh I think but
it was an example).

You missed the countdown procedure, I made that today for you and then you
said you did not need that.

Jay B. ask you why you use the diff and not complet normal the timespan, and
then you give an answer what does sound for me as, "are you crazy this I
need, this is the best".

The procedure that you say now that you need is not more than this (as Jay B
stated).

Dim starttime As DateTime = DateTime.Now
starttime = CDate("02/28/04 09:12:00 PM")
Dim ts As TimeSpan = starttime.Subtract(Now)
MessageBox.Show(ts.Days.ToString() & "d:" & ts.Hours.ToString() & _
"h:" & ts.Minutes.ToString() & "m:" & ts.Seconds.ToString() & "s")

If you had told this directly, CJ could have written this I think directly
for you.

But I do not see the sample watch and the clock which is ticking in this.

Cor
Nov 20 '05 #9
Cor and CJ,
You give me really the idea that you not are looking to the help you

get.

If you had not given me the information you did, I would still be
starring at this and going crazy...I am using all the code from both of
you and you have helped me very much in the past like last summer, I
don't know if you remember or not. I am truely greatful for your
knowledge and help...if you could just see the results of what it is I
am writing you would understand what I'm saying...Herferd Wagner is
helpful also. All of your help has led to my answers. As a programmer,
you know that it's hard to see what someone is doing sometimes.
Sometimes even I don't know what I am trying to do until the light comes
on.
Thanks,
Trint

.Net programmer
tr********@hotmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #10

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

Similar topics

6
by: James Turner | last post by:
I am trying to store formatted text (windows format) into a MySQL database and then retrieve it. The field in the database is a varchar. I cut and paste the test into a form field formatted, then...
5
by: Paul Lamonby | last post by:
Hi, I am generating a HTML formatted email in PHP, but I am getting the most bizarre error, it will randomly delete characters out of the HTML code while in transit to the address, therefore...
1
by: Kevin McBrearty | last post by:
Hello All, I'm trying to read a formatted text of strings and floats. I have looked through previous posts and couldn't deciper a good method. I'm new to python so any suggestions would be...
5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
2
by: JSheble | last post by:
I have a method in my class that needs to return formatted XML, with the carriage returns, linefeeds, and tabs... However, when I return oXml.OuterXml, the Xml is not formatted... Every example...
6
by: mesterak | last post by:
I have some log files I need to process via VB.NET and C# based applications. I read the entire contents of each file individually into a string variable using the StreamReader class (.ReadToEnd). ...
6
by: janama | last post by:
Hi, can such a thing be done somehow? aaa = self.aaa bbb = %s.%s % ('parent', 'bbb') Can you use strings or %s strings like in the above or
10
by: Ron | last post by:
I've got this simple program that will not build or run, any idea what I am doing wrong? Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
4
by: cybervigilante | last post by:
I sent HTML formatted email, using PHP, to my Yahoo address from my server, and it came out fine, styles and all. I sent it to my gmail address to test it and all I see is the raw html code. But I...
5
by: David Schwartz | last post by:
I've got some pre-formatted text and I'm not sure how to encode it in my xml to preserve its formatting. Any help would be appreciated! TIA, David
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.