C#: Getting the dates from file names

Getting the dates from file names.

using System.Linq;
using System.Collections.Generic;
class Test
{
    static void Main()
    {
        var items = new List<string>() {
                "foo_20120212",
                "foo_20120213",
                "foo_20120214",
                "foo_20120215",
                "baz_20120212",
                "baz_20120213",
                "baz_20120214",
                "baz_20120215"};

        var v = items.Select(a => a.Insert(a.Length - 2, "/"))
                                .Select(b => b.Insert(b.Length - 5, "/"))
                                .Select(c => new { date = c.Split('_')[1], str = c.Replace("/", "") })
                                .Select(d => new { date = String.Concat(d.date.Split('/').Reverse()), str = d.str })
                                .Select(e => new { date = e.date.Insert(e.date.Length - 4, "/"), str = e.str })
                                .Select(f => new { date = f.date.Insert(f.date.Length - 7, "/"), str = f.str })
                                .Select(g => new { date = DateTime.Parse(g.date), str = g.str })
                                .OrderByDescending(h => h.date).ToList();

        v.ForEach(x => Console.WriteLine(String.Format("date: {0}, str: {1}", x.date, x.str)));
        Console.ReadKey();
    }
}

date

HTML5: Date and time implementions in different browsers

This entry is part 21 of 34 in the series HTML5

There are some differences in the date and time implemention between the 4 major browsers Chrome, Mozilla, Safari and IE.

Notice from the screenshots below that Date and Time is only fully supported in Safari browser but Date and Time Local is supported in both Chrome and Safari.

Here the screenshot for Chrome:

chrome_datetime

Mozilla:

moz_datetime

Safari:

safari_datetime

IE:

ie_datetime

HTML5: Calendar and time

This entry is part 20 of 34 in the series HTML5

Before HTML5, we would use jqueryUI to create a calendar widget for user to pick a date and time.

You can refer to this earlier post regarding jqueryUI datepicker.

HTML5 offers the following date and time options:

  • Date and time
  • Date and time local – set to your local time with no UTC
  • Date
  • Time
  • Month
  • Week
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>Codecrawl.com: Date & Time</title>
</head>
<body>
<form>
    <label for='datetime_id'>Date & Time</label>
    <input required type='datetime' id='datetime_id' name='datetime'/>
    <input type='submit' value='Go'/>
    <br>
    <label for='datetime_local_id'>Date & Time Local</label>
    <input required type='datetime-local' id='datetime_local_id' name='datetime-local'/>
    <input type='submit' value='Go'/>
    <br>
    <label for='date_id'>Date</label>
    <input required type='date' id='date_id' name='date'/>
    <input type='submit' value='Go'/>
    <br>
    <label for='time_id'>Time</label>
    <input required type='time' id='time_id' name='time'/>
    <input type='submit' value='Go'/>
    <br>
    <label for='month_id'>Month</label>
    <input required type='month' id='month_id' name='month'/>
    <input type='submit' value='Go'/>
    <br>
    <label for='week_id'>Week</label>
    <input required type='week' id='week_id' name='week'/>
    <input type='submit' value='Go'/>
</form>
</body>
</html>

jQuery UI & Datepicker: Select a date range

This entry is part 4 of 14 in the series jQuery UI Datepicker

jQuery UI Datepicker – Select a Date Range

Select and define a date range.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Select a Date Range</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#from').datepicker({
                defaultDate: '+1w',
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function (selectedDate) {
                    $('#to').datepicker('option', 'minDate', selectedDate);
                }
            });
            $('#to').datepicker({
                defaultDate: '+1w',
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function (selectedDate) {
                    $('#from').datepicker('option', 'maxDate', selectedDate);
                }
            });
        });
    </script>
</head>
<body>

<label for='from'>From</label>
<input type='text' id='from' name='from'>
<label for='to'>to</label>
<input type='text' id='to' name='to'>

</body>
</html>
Try The Code

The defaultDate: ‘+1w’ will highlight a day 7 days from the current date.

Datepicker Widgets API Doc

jQuery UI & Datepicker: Restrict date range

This entry is part 6 of 14 in the series jQuery UI Datepicker

jQuery UI Datepicker – Restrict date range

Restrict the range of selectable dates with the minDate and maxDate options.

Set the beginning and end dates as actual dates (new Date(2009, 1 – 1, 26)), as a numeric offset from today (-20), or as a string of periods and units (‘+1M +10D’).

For the last, use ‘D’ for days, ‘W’ for weeks, ‘M’ for months, or ‘Y’ for years.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Restrict date range</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#datepicker').datepicker({ minDate: -20, maxDate: '+1M +10D' });
        });
    </script>
</head>
<body>

<p>Date: <input type='text' id='datepicker'></p>

</body>
</html>
Try The Code Datepicker Widgets API Doc