Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Date format

Hi all,

Just like to know if Delphi provide any calender function. That is if i will to send a date say 11 Feb 2000 to the function and it will tell me it is a Monday.

Thanks to all who help....

Regards,
Para

Comments

  • bikibiki Member Posts: 492
    [code]
    System::TDateTime x(2002,9,12); //Year, Month, Date
    ShowMessage(DayOfWeek(x)); //Returns 1 for Sunday, 2 for Monday...
    [/code]
    [size=2][red]

    [b]Bikram[/b][/red]
    [blue]http://www.geocities.com/nv5050[/blue]
    [red]**************************************[/red][/size]

  • ParadigmParadigm Member Posts: 77
    Hi all and biki,

    I understand the method of finding the dayofweek.

    Now i face with another problem. I were to read from a source which have this type of format.
    [code]
    04 Feb 2000 (D1D5)
    [/code]

    Therefore, i have capture this as a string variable. Then from this string var, i am suppose to find the day of the week from the date.

    e.g. above, i am suppose to know that it is Friday and display it out to another textbox.

    I would like to know how can i remove the (D1D5) and from 04 Feb 2000 convert to Friday.

    Thanks to all who help, Have a nice day

    Regards,
    Para
  • zibadianzibadian Member Posts: 6,349
    : Hi all and biki,
    :
    : I understand the method of finding the dayofweek.
    :
    : Now i face with another problem. I were to read from a source which have this type of format.
    : [code]
    : 04 Feb 2000 (D1D5)
    : [/code]
    :
    : Therefore, i have capture this as a string variable. Then from this string var, i am suppose to find the day of the week from the date.
    :
    : e.g. above, i am suppose to know that it is Friday and display it out to another textbox.
    :
    : I would like to know how can i remove the (D1D5) and from 04 Feb 2000 convert to Friday.
    :
    : Thanks to all who help, Have a nice day
    :
    : Regards,
    : Para
    :
    If the bracket '(' is always there, the process of removing it is simple:
    [code]
    MyDate := Trim(Copy(MyDate, 1, Pos('(', MyDate)-1));
    [/code]
    Then you need to convert this string to a TDateTime value. This might require that you split it into three strings, each delimited by a space. The code above with a small alteration will also do that trick:
    [code]
    MyDay := Copy(MyDate, 1, Pos(' ', MyDate)-1);
    Delete(MyDate, 1, Pos(' ', MyDate));
    MyMonth := Copy(MyDate, 1, Pos(' ', MyDate)-1);
    Delete(MyDate, 1, Pos(' ', MyDate));
    MyYear := MyDate;
    [/code]
    Now the month needs to be converted to an integer. Then you can use EncodeDate() to fill a TDateTime variable, and pass that variable to DayOfWeek() function.
    As always: for more info on all these functions see the online help files.
  • ParadigmParadigm Member Posts: 77
    If the bracket '(' is always there, the process of removing it is simple:
    [code]
    MyDate := Trim(Copy(MyDate, 1, Pos('(', MyDate)-1));
    [/code]
    Then you need to convert this string to a TDateTime value. This might require that you split it into three strings, each delimited by a space. The code above with a small alteration will also do that trick:
    [code]
    MyDay := Copy(MyDate, 1, Pos(' ', MyDate)-1);
    Delete(MyDate, 1, Pos(' ', MyDate));
    MyMonth := Copy(MyDate, 1, Pos(' ', MyDate)-1);
    Delete(MyDate, 1, Pos(' ', MyDate));
    MyYear := MyDate;
    [/code]
    Now the month needs to be converted to an integer. Then you can use EncodeDate() to fill a TDateTime variable, and pass that variable to DayOfWeek() function.
    As always: for more info on all these functions see the online help files.

    Hi all and zibadian,

    I did try to look up the online help file and know there is such functions existing. However, the problem is i don't really know much even after reading the help file.
    By the way, may i know what is inside the MyYear variable is
    '24 Feb 2000 (D1D5)' is in MyDate in the first place.

    Thanks zibadian

    Regards,
    Para
  • Andre YoungAndre Young USAMember Posts: 0

    ____ \ http://forcoder.org \ free video tutorials and ebooks about ( Python, C, MATLAB, Ruby, JavaScript, PHP, Objective-C, Assembly, Swift, Scratch, Go, PL/SQL, Java, Delphi, Visual Basic, Perl, C#, R, C++, Visual Basic .NET ABAP, Apex, Lisp, Dart, VBScript, Rust, SAS, Logo, Erlang, F#, Alice, Prolog, Crystal, Transact-SQL, Awk, Lua, D, Hack, Scala, Scheme, Ada, Kotlin, LabVIEW, ML, Bash, COBOL, FoxPro, Julia, Clojure, Fortran ) _

Sign In or Register to comment.