[PB] date functions

Source: Internet
Author: User

// 1. Zodiac (Year parameter: int ls_year return parameter: string ):
Mid (fill ('rat, ox, Tiger, Rabbit, dragon, Snake, horse, monkey, chicken, dog, pigs', 48), (mod (ls_year-1900,12) + 13) * 2-1, 2)

// 2. Days (Year parameter: int ls_year return parameter: string ):
Mid (fill ('a, B, C, E, Geng, Xin, Xi ', 40), (mod (ls_year-1924,10) + 11) * 2-1, 2) + mid (fill ('child ugly Yin Mao chen Wu Wei Xi Yu Hai ', 48), (mod (ls_year-1924,12) + 13) * 2-1, 2)

// 3. constellation (date parameter: Date ls_date return parameter: string ):
Mid (" Libra Scorpio shooter Capricorn", (month (ls_date) + sign (Day (ls_date) -(19 + INTEGER (mid ('20140901', month (ls_date), 1) + 1) * 4-3, 4) + 'hangzhou'
// 4. Determine the leap year (year parameter: int ls_year return parameter: int 0 = year, 1 = year ):
ABS (sign (mod (ABS (ls_year), 4) + sign (mod (ABS (ls_year), 100 )) + sign (mod (ABS (ls_year), 400), 2)-1)

// 5. Days of a month (date parameter: Date ls_date return parameter: INT ):
INTEGER (28 + INTEGER (mid ('3' + String (ABS (sign (mod (ABS (Year (ls_date), 4 )) + sign (mod (ABS (Year (ls_date), 100) + sign (mod (ABS (Year (ls_date), 400), 2)-1 )) + '20140901', month (ls_date), 1 )))

// 6. date of the last day of a month (date parameter: date ls_date return parameter: date ):
Date (year (ls_date), month (ls_date ), integer (28 + integer (mid ('3' + string (abs (sign (mod (abs (year (ls_date), 4 )) + sign (mod (abs (year (ls_date), 100) + sign (mod (abs (year (ls_date), 400), 2)-1 )) + '20140901', month (ls_date), 1 ))))

// 7. Calculate the date of the last day of a month (date parameter: date ls_date return parameter: date ):
A.
RelativeDate (date (year (ls_date) + sign (month (ls_date)-12) + 1, mod (month (ls_date) + 1, 13) + abs (sign (mod (month (ls_date) + 1, 13)-1), 1),-1)
B.
RelativeDate (date (year (ls_date) + integer (month (ls_date)/12), mod (month (ls_date), 12) + 1,1),-1)
// 8. Calculate the number of days of a month (date parameter: date ls_date return parameter: int ):
A.
Day (RelativeDate (date (year (ls_date) + sign (month (ls_date)-12) + 1, mod (month (ls_date) + 1, 13) + abs (sign (mod (month (ls_date) + 1, 13)-1), 1),-1 ))
B.
Day (relativedate (date (year (ls_date) + INTEGER (month (ls_date)/12), MOD (month (ls_date), 12) + 1,1),-1 ))

// 9. The day of a week in a month -- The dayname function of the petabyte system (date parameter: Date ls_date return parameter: string ):
'Week' + mid ('february 23, ', (mod (Year (ls_date)-1 + int (Year (ls_date)-1)/4) -int (Year (ls_date)-1)/100) + int (Year (ls_date)-1)/400) + daysafter (date (year (ls_date ), ), ls_date) + 1) * 2)

// 10. Calculate the relative date after several months (date parameter: Date ls_date month (negative value): int ls_add_month return parameter: Date ):
Date (year (ls_date) + int (month (ls_date) + ls_add_month)/13), long (mid (fill ('123', 48 ), (mod (month (ls_date) + ls_add_month-) + 13) * 2-), Day (ls_date) -INTEGER (right (left (string (Day (relativedate (date (year (ls_date) + int (month (ls_date) + ls_add_month)/13) + sign (long (mid (fill ('20140901', 48), (mod (month (ls_date) + ls_add_month
-010203040506070809101112) + 13) * 2-)-12) + 1, mod (long (mid (fill ('20140901', 48), (mod (month (ls_date) + ls_add_month-010203040506070809101112) + 13) * 2-) + abs (sign (mod (long (mid (fill ('20140901', 48 ), (mod (month (ls_date) + ls_add_month-) + 13) * 2-) +)-1), 1),-1 ))
-Day (ls_date), '00') + '000000', 5), 3)/00000)

// 11. Calculate the number of weeks in the current year for a certain day (date parameter: date ls_date return parameter: int ):
// A. The first day of the week is Sunday
// A1
Abs (int (-(daysafter (RelativeDate (date (year (ls_date), 1, 1),-mod (year (ls_date)-1 + int (year (ls_date) -1)/4)-int (year (ls_date)-1)/100) + int (year (ls_date)-1)/400) +) + 1), ls_date) + 1)/7 )))
// A2 (using the DayNumber function)
Abs (int (-(daysafter (RelativeDate (date (year (ls_date), 1, 1),-DayNumber (date (year (ls_date), 1, 1), ls_date) + 1)/7 )))

// B. Monday
// B1
ABS (INT (-(daysafter (relativedate (date (year (ls_date), 6012345),-INTEGER (mid ('20140901', MOD (Year (ls_date) -1 + int (Year (ls_date)-1)/4)-int (Year (ls_date)-1)/100) + int (Year (ls_date) -1)/400) +), 1), ls_date) + 1)/7 )))
// B2 (use the daynumber function)
ABS (INT (-(daysafter (relativedate (date (year (ls_date), 6012345),-INTEGER (mid ('20140901', daynumber (date (year (ls_date ), 1, 1), 1), ls_date) + 1)/7 )))
// 12. Calculate the number of weeks (date: ls_date_1 (required), ls_date_2 (previous day), and INT) of a day relative to a previous date ):
// Note: ls_date_1> ls_date_2
// A. The first day of the week is Sunday
// A1
ABS (INT (-(daysafter (relativedate (ls_date_2,-Mod (Year (ls_date_2)-1 + int (Year (ls_date_2)-1)/4) -int (Year (ls_date_2)-1)/100) + int (Year (ls_date_2)-1)/400) + daysafter (date (year (ls_date_2 ), ), ls_date_2) + 1), ls_date_1) + 1)/7 )))
// A2 (using the daynumber function)
Abs (int (-(daysafter (RelativeDate (ls_date_2,-DayNumber (ls_date_2) + 1), ls_date_1) + 1)/7 )))

// B. Monday
// B1
Abs (int (-(daysafter (RelativeDate (ls_date_2,-integer (mid ('000000', mod (year (ls_date_2)-1 + int (year (ls_date_2) -1)/4)-int (year (ls_date_2)-1)/100) + int (year (ls_date_2)-1)/400) + daysafter (date (year (ls_date_2),), ls_date_2) +), 1), ls_date_1) + 1)/7 )))
// B2 (use the DayNumber function)
Abs (int (-(daysafter (RelativeDate (ls_date_2,-integer (mid ('000000', DayNumber (ls_date_2), 1), ls_date_1) + 1) /7 )))

Date of the last day of a month
RelativeDate (date (year (ld_1) + integer (month (ld_1)/12), mod (month (ld_1), 12) + 1,1),-1)
Get last day
Day (statement above)
Leap year (1 is a leap year, 0 is a year)
Integer (day (RelativeDate (date (year (ld_1), 3, 1),-1)/29)
Number of weeks of the current date
Integer (daysafter (date (year (ad_date), 1, 1), ad_date)/7) + 1 + integer (daynumber (date (year (ad_date), 1, 1) + mod (daysafter (date (year (ad_date), 1, 1), ad_date), 7)-1)/7)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.