Batch file to delete files older than N days

Enjoy: forfiles -p “C:\what\ever” -s -m *.* -d <number of days> -c “cmd /c del @path” See forfiles documentation for more details. For more goodies, refer to An A-Z Index of the Windows XP command line. If you don’t have forfiles installed on your machine, copy it from any Windows Server 2003 to your Windows XP machine at %WinDir%\system32\. … Read more

Converting ISO 8601-compliant String to java.util.Date

Unfortunately, the time zone formats available to SimpleDateFormat (Java 6 and earlier) are not ISO 8601 compliant. SimpleDateFormat understands time zone strings like “GMT+01:00” or “+0100”, the latter according to RFC # 822. Even if Java 7 added support for time zone descriptors according to ISO 8601, SimpleDateFormat is still not able to properly parse … Read more

Get difference between 2 dates in JavaScript? [duplicate]

Here is one way: const date1 = new Date(‘7/13/2010′); const date2 = new Date(’12/15/2010’); const diffTime = Math.abs(date2 – date1); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); console.log(diffTime + ” milliseconds”); console.log(diffDays + ” days”); Observe that we need to enclose the date in quotes. The rest of the code … Read more

How to print a date in a regular format?

The WHY: dates are objects In Python, dates are objects. Therefore, when you manipulate them, you manipulate objects, not strings or timestamps. Any object in Python has TWO string representations: The regular representation that is used by print can be get using the str() function. It is most of the time the most common human … Read more

How to check whether an object is a date?

As an alternative to duck typing via typeof date.getMonth === ‘function’ you can use the instanceof operator, i.e. But it will return true for invalid dates too, e.g. new Date(‘random_string’) is also instance of Date date instanceof Date This will fail if objects are passed across frame boundaries. A work-around for this is to check … Read more

How to subtract days from a plain Date?

Try something like this: var d = new Date(); d.setDate(d.getDate()-5); Note that this modifies the date object and returns the time value of the updated date. var d = new Date(); document.write(‘Today is: ‘ + d.toLocaleString()); d.setDate(d.getDate() – 5); document.write(‘<br>5 days ago was: ‘ + d.toLocaleString());

How to get the last day of the month?

calendar.monthrange provides this information: calendar.monthrange(year, month)     Returns weekday of first day of the month and number of days in month, for the specified year and month. >>> import calendar >>> calendar.monthrange(2002, 1) (1, 31) >>> calendar.monthrange(2008, 2) # leap years are handled correctly (4, 29) >>> calendar.monthrange(2100, 2) # years divisible by 100 but not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)