international Date

Josh Mellicker josh at dvcreators.net
Tue Dec 19 19:09:07 EST 2006


Just in the remote chance this is at all helpful to anyone, here are  
my SQL date/time conversion routines, I'm sure they could be  
streamlined...

Also, HAPPY HANNUKAH AND XMAS EVERYONE!!!

-------------------------------------------------
-- NowSQLTimeStamp
-------------------------------------------------
FUNCTION NowSQLTimeStamp
     return (convert2SQLDate(the english date) && convert2SQLTime(the  
english time))
END NowSQLTimeStamp

-------------------------------------------------
-- RegDateFromSQL
-------------------------------------------------
FUNCTION RegDateFromSQL pInDate
     set the itemdelimiter to "-"
     put item 2 of pInDate & "/" & item 3 of pInDate & "/" &  char 3  
to 4 of item 1 of pInDate into tRegDate
     set the itemdelimiter to "/"
     IF char 1 of item 1 of tRegDate = 0 THEN delete char 1 of item 1  
of tRegDate
     IF char 1 of item 2 of tRegDate = 0 THEN delete char 1 of item 2  
of tRegDate
     IF tRegDate = "//" THEN put empty into tRegDate
     return tRegDate
END RegDateFromSQL

-------------------------------------------------
-- RegTimeFromSQL
-------------------------------------------------
FUNCTION RegTimeFromSQL pInTime
     set the itemdelimiter to ":"
     delete the last item of pInTime
     IF item 1 of pInTime > 12 THEN
         put item 1 of pInTime - 12 into item 1 of pInTime
         put " PM" after pInTime
     ELSE IF item 1 of pInTime = 12 THEN
         put " PM" after pInTime
     ELSE
         put " AM" after pInTime
         IF char 1 to 2 of pInTime = "00" THEN
             put "12" into char 1 to 2 of pInTime
         ELSE IF char 1 of pInTime = 0 THEN
             delete char 1 of pInTime
         END IF
     END IF
     IF pInTime = " AM" THEN put empty into pInTime
     return pInTime
END RegTimeFromSQL

-------------------------------------------------
-- Convert2SQLDate
-------------------------------------------------
FUNCTION Convert2SQLDate pOldDate
     IF pOldDate = "" THEN
         put "" into tNewDate
     ELSE
         set the itemdel to "/"
         IF the number of chars of item 1 of pOldDate = 1 THEN put  
"0" before pOldDate
         IF the number of chars of item 2 of pOldDate = 1 THEN put  
"0" before item 2 of pOldDate
         IF the number of chars of item 3 of pOldDate = 2 THEN put  
"20" before item 3 of pOldDate
         put item 3 of pOldDate & "-" & item 1 of pOldDate & "-" &  
item 2 of pOldDate into tNewDate
     END IF
     return tNewDate
END Convert2SQLDate

-------------------------------------------------
-- Convert2SQLTime
-------------------------------------------------
FUNCTION Convert2SQLTime pOldTime
     set the itemdel to ":"
     IF the last word of pOldTime = "PM" AND (item 1 of pOldTime <>  
"12") THEN
         add 12 to item 1 of pOldTime
     END IF
     IF the last word of pOldTime = "AM" AND (item 1 of pOldTime =  
"12") THEN
         put "00" into item 1 of pOldTime
     END IF
     IF the number of chars of item 1 of pOldTime = 1 THEN put "0"  
before pOldTime
     delete the last word of pOldTime
     put ":00" after pOldTime

     IF pOldTime = ":00" THEN
         put empty into pOldTime
       END IF
         return pOldTime
END Convert2SQLTime

-------------------------------------------------
-- DateAndTimeFromSQL
-------------------------------------------------
FUNCTION DateAndTimeFromSQL pSQLDateAndTime
     put word 1 of pSQLDateAndTime into tDate
     IF tDate = "0000-00-00" THEN put "" into tDate
     put word 2 of pSQLDateAndTime into tTime
     IF tTime = "00:00:00" THEN put "" into tTime
     IF tDate & tTime = "" THEN
         --return ""
     ELSE
         put RegDateFromSQL(tDate) && RegTimeFromSQL(tTime) into tReturn
     END IF
     return tReturn
END DateAndTimeFromSQL


On Dec 19, 2006, at 3:13 AM, Sivakatirswami wrote:

> Am I the  only one who continues to be perplexed as to why the
> international date format is not a standard engine function?
>
> Hypenated: YYYY-MM-DD,  zero padded comes standard with SQL
> but in Rev we have to do little dances like:
>
> FUNCTION internationalDate tDate
>     convert tDate to dateitems
>     IF len(item 2 of tDate<2) THEN put "0" before item 2 of tDate
>     IF len(item 3 of tDate<2) THEN put "0" before item 2 of tDate
>     return   (item 1 of  tDate &"-" & item 2 of tDate &"-" & item 3 of
> tDate)
> END internationalDate
>
> ?? am I missing  something?
>
> Worthy of a feature request?
>
> Sivakatirswami
> www.himalayanacademy.com
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list