从天数开始的日期 [英] Date from Number of Days

查看:55
本文介绍了从天数开始的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,乍一看似乎不难理解。但是,到目前为止,答案已经逃过了我。我有一个旧的

数据库文件,其中存储的日期为天数。

一个例子是:36,525代表01/01/1900。起点日期被视为:

00/00/0000。我通过帮助查看并使用了Google并且没有真正找到答案。

我知道Leap Years也需要考虑。

有关从哪里开始的任何建议?

james

I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james

推荐答案

James,

使用DateTime.AddDays查找给定的日期自well

已知以来的天数日期。或者转向另一个方向使用DateTime.Subtract来查找自众所周知以来的天数

天数。日期。


问题你要的是Datetime.MinDate是01/01/0001

而不是00/00/0000,我只需加上或减去

的差异需要几天......


您可能需要考虑一对函数,例如:


Private Const BaseDate As DateTime =# 1/1/1900#

私有Const BaseDays为整数= 36525

公共函数ToFileDateTime(ByVal值为DateTime)为整数

Dim ts As TimeSpan = value.Date.Subtract(BaseDate)

返回CInt(ts.TotalDays)+ BaseDays

结束功能


公共函数FromFileDateTime(ByVal days As Integer)As DateTime

返回BaseDate.AddDays(天 - BaseDays)

结束函数


BaseDate& BaseDays是你的众所周知的约会。


当然如果您需要01/01/0001之前的日期,那么您可能会遇到问题...


希望这会有所帮助

Jay


" james" < jjames700ReMoVeMe at earthlink dot net>在消息中写道

news:ed ************** @ TK2MSFTNGP11.phx.gbl ...
James,
Use DateTime.AddDays to find a date given the number of days since a "well
known" date. Or to go the other direction use DateTime.Subtract to find the
number of days since a "well known" date.

The "problem" you are going to have is that Datetime.MinDate is 01/01/0001
as opposed to 00/00/0000, I would simply add or subtract the difference in
days as needed...

You may want to consider a pair of functions, something like:

Private Const BaseDate As DateTime = #1/1/1900#
Private Const BaseDays As Integer = 36525

Public Function ToFileDateTime(ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subtract(BaseDate)
Return CInt(ts.TotalDays) + BaseDays
End Function

Public Function FromFileDateTime(ByVal days As Integer) As DateTime
Return BaseDate.AddDays(days - BaseDays)
End Function

Where BaseDate & BaseDays are your "well known" date.

Of course if you need dates pre 01/01/0001 then you may have a problem...

Hope this helps
Jay

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:ed**************@TK2MSFTNGP11.phx.gbl...
我有一个问题,乍一看似乎并不难理解。
但是,到目前为止,答案已经逃过了我。我有一个旧的数据库文件,其中存储的日期为天数。
一个例子是:36,525代表01/01/1900。起点日期
被认为是:
00/00/0000。我已经通过帮助查看并使用了Google并且没有真正找到答案。
我知道Leap Years也需要考虑。
有关从哪里开始的任何建议? james
I have a problem that at first glance seems not that hard to figure out.
But, so far, the answer has escaped me. I have an old database file that
has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is
considered to be :
00/00/0000. I have looked thru Help and used Google and have not really
found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james



James,


从未做过,但我想我会先带它在00:00:00时回到日期的刻度

并使用正常的日期时间格式。

http://msdn.microsoft.com/library/de。 ..tickstopic.asp


我希望这会有所帮助


Cor
James,

Never done, however I think I would first bring it back to the date in ticks
at 00:00:00 hour and than use the normal datetime format.

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

I hope this helps something

Cor

Jay,很棒的解决方案!这两个功能都很有效。在我的大脑开始并想出如何正确使用它们之后:-)

我非常感谢你的帮助。我遇到的问题是Dataflex数据库系统

使用00/00/0000作为基准日期。并且数据库引擎在原始的

(基于DOS)文件系统中以十六进制格式存储该数字。我可以找到并提取数字,但是,我无法确切地知道数据是如何转换为有意义的日期。我正在学习如何更加尊重现在编写数据库转换器的人!

james

" Jay B. Harlow [MVP - Outlook]" < JA ************ @ msn.com>在消息新闻中写道:Oa ************** @ TK2MSFTNGP14.phx.gbl ...
Jay, great solution! Both functions work very well. After my brain kicked in and figured out how to use them correctly :-)
I really do appreciate your help. The problem I had encountered was that the Dataflex database system
used 00/00/0000 as the Base Date. And that the database engine stored that number in Hex in the original
(DOS based) file system. I could find and extract the numbers, but, I could not find out exactly how the data was being
converted to a meaningful date. I am learning to have a lot more respect for people that write database converters now!
james
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:Oa**************@TK2MSFTNGP14.phx.gbl...
James,
使用DateTime.AddDays查找给出自众所周知以来的天数的日期。日期。或者向另一个方向使用
DateTime.Subtract来查找自众所周知以来的天数。日期。

问题你要说的是Datetime.MinDate是01/01/0001而不是00/00/0000,我只是根据需要添加或者减去天数差异......

Private Const BaseDate As DateTime =#1/1 / 1900#
Private Const BaseDays As Integer = 36525
Public Function ToFileDateTime(ByVal value As DateTime)As Integer
Dim ts As TimeSpan = value.Date.Subtract(BaseDate)
返回CInt(ts.TotalDays)+ BaseDays
结束函数

公共函数FromFileDateTime(ByVal days As Integer)As DateTime
返回BaseDate.AddDays(天 - BaseDays)
结束函数

BaseDate &安培; BaseDays是你的众所周知的约会。

当然如果您需要01/01/0001之前的日期,那么您可能会遇到问题...

希望这有帮助
Jay
詹姆斯 < jjames700ReMoVeMe at earthlink dot net>在消息新闻中写道:ed ************** @ TK2MSFTNGP11.phx.gbl ...
James,
Use DateTime.AddDays to find a date given the number of days since a "well known" date. Or to go the other direction use
DateTime.Subtract to find the number of days since a "well known" date.

The "problem" you are going to have is that Datetime.MinDate is 01/01/0001 as opposed to 00/00/0000, I would simply add or
subtract the difference in days as needed...

You may want to consider a pair of functions, something like:

Private Const BaseDate As DateTime = #1/1/1900#
Private Const BaseDays As Integer = 36525

Public Function ToFileDateTime(ByVal value As DateTime) As Integer
Dim ts As TimeSpan = value.Date.Subtract(BaseDate)
Return CInt(ts.TotalDays) + BaseDays
End Function

Public Function FromFileDateTime(ByVal days As Integer) As DateTime
Return BaseDate.AddDays(days - BaseDays)
End Function

Where BaseDate & BaseDays are your "well known" date.

Of course if you need dates pre 01/01/0001 then you may have a problem...

Hope this helps
Jay

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:ed**************@TK2MSFTNGP11.phx.gbl...
我有一个问题,乍一看似乎并不难弄清楚。但是,到目前为止,答案已经逃过了我。我有一个旧的
数据库文件,其中存储的日期为天数。
一个例子是:36,525代表01/01/1900。起点日期被认为是:
00/00/0000。我已经通过帮助查看并使用了Google并且没有真正找到答案。
我知道Leap Years也需要考虑。
关于从哪里开始的任何建议?
james
I have a problem that at first glance seems not that hard to figure out. But, so far, the answer has escaped me. I have an old
database file that has the date(s) stored in it as number of days.
An example is: 36,525 represents 01/01/1900. The starting point date is considered to be :
00/00/0000. I have looked thru Help and used Google and have not really found an answer.
I know that Leap Years need to be accounted for too.
Any suggestions on where to start ?
james




这篇关于从天数开始的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆