Solved

Getting the correct format of Date

Posted on 2001-06-21
13
214 Views
Last Modified: 2013-12-18
I have a field in DateTime format. if the user choose today's date, the field will show "22/06/2001" but when i get the value from my code, it shows me "06/22/2001" as a result, i encounter an error when i do the following :

FromDate = Datenumber(Year(From), Month(From), Day(From))

I've checked the regional settings, the date format is "dd/MM/yyyy". is there any way that i can get the value of the date and force it to be formatted to "dd/MM/yyyy"?

Thanks.
0
Comment
Question by:irene79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 13

Expert Comment

by:CRAK
ID: 6217263
Assuming that "From" is yout DateTime-field, and FromDate is a NotesDateTime object, can't you simply use:

Set FromDate = document.From(0)


Or use pre-format it as you request, using format:

FormattedFrom = format$(From, "dd/mm/yyyy")


Another option could be retrieving the clients international settings first through NotesSession.International. Using NotesInternational.DateSep and NotesInternational.IsDateDMY, -.IsDateMDY and -.IsDateYMD, you could split the original string in three pieces and feed those (in the correct order) to your DateNumber function.
0
 

Author Comment

by:irene79
ID: 6217300
i've tried using format to format it. but it did not work. the output is still "06/22/2001 12:00:00 AM"

Can you show me the code for using the international settings and the splitting?
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6217314
Did you also check the servers settings ?
Did you check the fields properties, does he use custom settings or system settings ?
Here's a link to a question with almost the same problem
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20121730

Greets,
Sloeber
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:CRAK
ID: 6217864
I have worked with D/M/Y clients on M/D/Y servers before.
The solutions of splitting the date could work but isn't my first recommendation. As the problem may also occur in other applications in your organisation (now or in future...) I guess you want an easy-to-remember-solution!

Can you provide more detail? How to you retrieve the data from the date/time field and put it into "From"? I may be able to look a solution in my older work then.

One thing is sure: never trust the help regarding formula's accepting both D/M/Y and M/D/Y: how should in interprete 1/2/2001? 1st of Feb or 2nd of Jan?
0
 

Author Comment

by:irene79
ID: 6220585
here's my code :

Dim ws As New NotesUIWorkspace
Dim uidocCur As NotesUIDocument
Set uidocCur = ws.CurrentDocument
     
Dim sDateFrom As String
     
sDateFrom = uidocCur.FieldGetText("datFrom")

"datFrom" is a field on the form of datetime type. not sure if tis info. is enuff. let me know if i need to provide more details.
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6223379
You need to define sDateFrom as a Variant variable, this way it will contain your date as a date variable in script. Now when you set the datefield using this variable, it doesn't matter what format it was originally entered as. Notes will automatically format it the way it should.
BTW: For web applications Notes will always display the date according the server's Default User's international settings.

Regards,
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6223513
So the error was a "Type mismatch", right?
I expected errors caused by month > 12....

Try:

Dim Ws As New NotesUIWorkspace
Dim UIDoc As NotesUIDocument
Set UIDoc = Ws.CurrentDocument

Dim sDateFrom As New NotesDateTime(UIDoc.FieldGetText("datFrom"))

' additional handling to prove it's working
Call sDateFrom.AdjustDay(1)
Messagebox sDateFrom.LsLocalTime
0
 

Expert Comment

by:vgalvin052701
ID: 6224203
Is your client Windows 95/98?
If it is, there is a setting in win.ini called idate=0.
Change the entry to be idate=1 and your fields will display as 22/6/2001.
idate=0 gives you the format 6/22/2001
Hope this helps
0
 

Author Comment

by:irene79
ID: 6225890
CRAK: yes i got the error of type mismatch. will try your method and get back to you.

vqalvin : my client is windows95. but im trying to set the date format to dd/mm/yyyy without depending on the settings of the user's pc.
0
 

Author Comment

by:irene79
ID: 6226047
CRAK: the sDateFrom.LsLocalTime works! does that mean that everytime i need to retrieve a date field from the form i have to use LsLocalTime? in my other date field, i will get a type mismatch error if i do not put LsLocaltime.
0
 
LVL 13

Accepted Solution

by:
CRAK earned 50 total points
ID: 6226668
The NotesDateTime objects LS-properties return actual dates, represented as a number of days after (+) or before (-) a certain date (I would have to look that up: it's in the help somewhere...). Since it is in fact a number, you can still handle that date, like adjusting or formatting it.
If you would use properties returning a string, like "LocalTime" it would be preformatted as defined by the OS. For notes clients that would be the OS on which Notes is running, for browsers that would be the servers settings. And as different machines could have different settings, you cannot predict where the date, the month or the year went, nor use the year(), month() and day() functions.

In fact it's quite similar to currency fields:
If your system is defined to use USD ("$") and you've filled out 100 you'd expect things not to fail.
Now if that document is opened by somebody in Italy it might read ITL 100; quite a different budget!
If you would have converted it to a string "$ 100", it would read fine in Italy, but -without conversion- you would not be able to add another $ 50.

So you always need to be very careful with things depending on international settings!

My answer to your question would be YES: if you want to use the date for further handling make sure you keep date/time values stores as date/time objects, and use either LSLocalTime or LSGMTtime.
0
 

Author Comment

by:irene79
ID: 6226707
Thanks CRAK!! :)
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6226749
You're welcome!
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question