Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Better way to convert date format

4,923 views
Skip to first unread message

David

unread,
Dec 7, 2003, 2:22:06 AM12/7/03
to
I'm trying to extract the date from an editmask control and use it as a
retrieval argument. The date format in the editmask control is DD/MM/YYYY,
the stored proc expects a datetime type.

This is (approximately) how I've done the conversion, I'm writing this from
home. It works, but it's very ugly; the problem is that datetime() will
only accept a date that's in the format YYYY/MM/DD.

Can someone suggest a better way?

ls_date = string(date(em_control.Text), "YYYY/MM/DD")

ldt_datetime = datetime(date(ls_date))

Olivier

unread,
Dec 8, 2003, 6:14:29 AM12/8/03
to
If your code works, then this will work :
ldt_datetime = datetime(date(em_control.Text))

But i suggest you use an external datatwindow instead of an edit mask :
ldt_datetime = dw_frm.getItemDateTime (1, "foo")

On 6 Dec 2003 23:22:06 -0800,
in sybase.public.powerbuilder.general

Matthew Chestnut

unread,
Dec 8, 2003, 2:05:27 PM12/8/03
to
Be careful using the Powerscript Date(string datestring) function
since it uses the Regional Settings in the string-to-date conversion.
We use the Date(int year,int month, int day) function instead.

Mark Calder

unread,
Oct 2, 2013, 3:42:33 PM10/2/13
to
Same exact problem but I cannot rely on users to have their regional settings configured to MM/dd/yyyy. If someone has gotten all clever and configured their regional settings for dd/MM/yyyy then I have large problems (working in medical records)

It seems ludicrous that they have a string(date, format) function but they don't have a Date(string, format) function to perform the reverse.

So I guess I'll make a string parser that is specific the the date format I have chosen. Would be nice to see a post of a general purpose one that used a passed in format string to drive its parsing. Or maybe I need to upgrade away from powerbuilder 11? To have one conversion function and not the reverse seems a bit incomplete.
ParseStringAsDate(string s_date, string s_format) returns Date

pops...@gmail.com

unread,
Sep 2, 2019, 10:41:17 PM9/2/19
to
There is a concrete solution to your problem. Mark's suggestion for creation of ParseStringAsDate() function is also a great solution. But here's a simple one.

1) Instead of an editmask, create an external datawindow with date as type of the column. You can apply mask on it.
2) Or you can use an editmask, but make sure the date entry has a format of 'DD-MMM-YYYY'. Example is '11-Mar-2019'. In this way, regardless of the regional setting you day/month will always pick up the correct value.

Then simply convert it to date:
Date ldt_date
String ls_date
ls_date = em_1.Text
ldt_date = Date(ls_date)
0 new messages