1

My application behaves differently when I work on Windows Server 2008 R2.

When I converted my PowerScript to .net project, today() 's functions returns the value as date along with time (date+time) instead of only date.

ldt_date = today()

any suggestions?

Hugh Brackett
  • 2,706
  • 14
  • 21
Abdelwahed
  • 1,694
  • 4
  • 21
  • 31

3 Answers3

2

you can add ToString formatting

yourdate.ToString("d"); 
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
1

That is normal .NET behavior.

        DateTime dt = DateTime.Today;
        Console.WriteLine(dt.ToString);  //output 6/23/2012 12:00:00 AM

if you want date only (6/23/2012) try:

        DateTime dt = DateTime.Today;
        Console.WriteLine(dt.ToShortDateString());  //output 6/23/2012
GrayFox374
  • 1,742
  • 9
  • 13
0

In .NET you can get the only date part of DateTime variable using DateTime.Date Property

It's like

 yourdate.ToString("d")

Example

DateTime date1 = new DateTime(2008, 6, 1, 7, 47, 0);
Console.WriteLine(date1.ToString());

// Get date-only portion of date, without its time.
DateTime dateOnly = date1.Date;
// Display date using short date string.
Console.WriteLine(dateOnly.ToString("d"));
Kevin Brock
  • 8,874
  • 1
  • 33
  • 37
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263