Simple question about date - Today - not updating

netchicken

Active Member
Licensed User
Longtime User
I feel somewhat embarrassed asking this, as its going to be blindingly obvious, but i can't get todays date to show, or update.

I need a Julian date so I can subtract one date from another date held in the database to get a date difference. Both dates are / will be created using the same Today calculation.

I have read and tried all the posts here, and I can get the program to generate a number, only it never updates.

For example this structure is right out of the manual but it gives 1, every day I run it. :)

Other times it gave a number of 700101 when I used yymmdd for the format. But no matter what format I used it never gave a number that changed every day.

Dim now As Long
Dim today As String
DateTime.DateFormat = "dddd"
today = DateTime.Date(now)
lbltoday.text = today

Even using Dim today As Long makes no difference.

What am I doing wrong?
 
Last edited:

netchicken

Active Member
Licensed User
Longtime User
Thanks guys, indeed it seems to be working now :)

However I seem to get a number now that changes all the time!

Dim now As Long
now = DateTime.Now
Dim today As String
DateTime.DateFormat = "yymmdd"
today = DateTime.Date(DateTime.now)

gives 115728 and a few seconds later 115928 and then 110028 and then 110128 110228
the middle two digits change constantly with 11 and 28 being constant being I suppose yy and dd rather than the julian date I am after.

Changing
DateTime.DateFormat = "yymmdd"
to dddd or even "" doesn't seem to make any difference with the same number type as above returning.
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Days Between Dates

Post this sub and send it two dates as a string and it will return the days between them.

B4X:
Sub DateNOD(CurrentDate As String, OtherDate As String) As Int
   Dim CurrDate, OthDate, MyNewDate As Long
   CurrDate = DateTime.DateParse(CurrentDate)
   OthDate = DateTime.DateParse(OtherDate)
   NumOfDays = (CurrDate-OthDate)/(DateTime.TicksPerDay)
   Return NumOfDays
End Sub

Thanks,

Margret
 
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
Thanks margret, but I need to generate Todays date, to subtract it from a stored date. its generating the julian date for today that doesn't work for me.

Looking at an example from Klaus he used

jd=DateTime.DateParse(DateTime.Date(DateTime.Now))

http://www.b4x.com/forum/basic4andr.../7019-about-datetime-zone-time.html#post40347

that gives me 1296126300000

this increments in 60000 units

So today= (DateTime.DateParse(DateTime.Date(DateTime.Now))/10000)

129612672 incrementing every second I think.
129612744

without the date format DateTime.DateFormat = "yymmdd" I get

1317121200000 which doesn't seem to change at all.

I find it puzzling :)
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Days Between Dates

Hello Again,

Use this sub for the current date. You would call the other sub like:

DaysBetween = DateNOD(Date, "01/12/1961" or your variable here)

B4X:
Sub Date As String 
   MyDateDay = DateTime.Date(DateTime.Now)
   Return MyDateDay
End Sub

This works fine I use it in an APP and over 500+ are using it now. If your dates are JD, convert them to "01/01/1960" format before you pass them to get the days between them. If you can't get it working. Send me or post two date samples in two different strings and I'll fix the code where it will work.

Thanks,

Margret
 
Last edited:
Upvote 0

Rioven

Active Member
Licensed User
Longtime User
Just my take...

@netchicken, You may consider to include the previous time saved as well to give an accurate number of days. ie. with decimal places or may consider to return Number of days and hours once this routine called.

something like code below, but I am sure, there is shortcut for this.

B4X:
[COLOR="Blue"]Dim [/COLOR]PreviousDate,PreviousTime [COLOR="Blue"]As [/COLOR][COLOR="MediumTurquoise"]String[/COLOR]

      PreviousDate="09/26/2011"
      PreviousTime="12:45:12"
      
      [COLOR="Blue"]Dim [/COLOR]TotalPreviousTicks  [COLOR="blue"]As [/COLOR][COLOR="MediumTurquoise"]Long   [/COLOR]
   
                     
      TotalPreviousTicks= [COLOR="Blue"]DateTime[/COLOR].DateParse(PreviousDate) + [COLOR="blue"]DateTime[/COLOR].TimeParse(PreviousTime)- [COLOR="blue"]DateTime[/COLOR].DateParse([COLOR="blue"]DateTime[/COLOR].Date([COLOR="blue"]DateTime[/COLOR].Now))
      
      
      NumberOfDays=([COLOR="blue"]DateTime[/COLOR].Now-TotalPreviousTicks)/[COLOR="blue"]DateTime[/COLOR].TicksPerDay
 
Upvote 0

netchicken

Active Member
Licensed User
Longtime User
Thanks for everyone's help, I don't know if my system is screwy but I finally got this to generate a julian date. I hope anyone else looking into this might benefit from it.

Dim now As Long
Dim today As Long

today= (DateTime.DateParse(DateTime.Date(DateTime.Now))/(DateTime.TicksPerDay))
 
Upvote 0

droman

Member
Licensed User
Longtime User
Is it possible to know the number of days, hours, minutes and seconds until a specific date?
 
Upvote 0

peggjones

Active Member
Licensed User
Longtime User
Can anyone help me please?

When I run the following code


Date
DateNOD(Date,"01/12/1961")

I Get unparsable date "01/12/1961"

Any ideas why this might be, I think I am doing what is suggested above?
 
Upvote 0
Top