Created
December 31, 2022 12:00
-
-
Save mdzzohrabi/e2f052ad922b28a659db8f88f4368436 to your computer and use it in GitHub Desktop.
Generate Jalali Dates for SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let startDate = new Date('2010-01-01'); | |
let endDate = new Date('2060-12-29'); | |
let date = new Date(startDate); | |
let result = ''; | |
while (date < endDate) { | |
let monthName = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { month: 'long' }).format(date); | |
let month = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { month: 'numeric' }).format(date); | |
let weekDayName = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { weekday: 'long' }).format(date); | |
let weekDay = ['شنبه','یکشنبه','دوشنبه','سهشنبه','چهارشنبه','پنجشنبه','جمعه'].indexOf(weekDayName) + 1; | |
let year = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { year: 'numeric' }).format(date); | |
let day = new Intl.DateTimeFormat('fa-IR-u-nu-latn', { day: 'numeric' }).format(date); | |
let jalaliDate = new Intl.DateTimeFormat('fa-IR-u-nu-latn').format(date); | |
let dateFormat = new Intl.DateTimeFormat('en-US').format(date); | |
result += (`\nINSERT INTO CM.JalaliDate (MiladiDate, JalaliDate, MonthName, WeekDayName, WeekDay, Month, Year, Day) VALUES ('${dateFormat}', '${jalaliDate}', N'${monthName}', N'${weekDayName}', ${weekDay}, ${month}, ${year}, ${day})`); | |
date.setDate(date.getDate() + 1) | |
} | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment